Open Search
    StackBufferAllocator< BLOCK_SIZE, LIFO, ALLOCATOR > Class Template Reference

    #include <stackbufferallocator.h>

    Detailed Description

    template<Int BLOCK_SIZE, Bool LIFO, typename ALLOCATOR = DefaultAllocator>
    class maxon::StackBufferAllocator< BLOCK_SIZE, LIFO, ALLOCATOR >

    A StackBufferAllocator can be used if a large number of allocations shall be done in the sequel, and either all of those allocations will be freed together at a later point, or they will be freed in reverse order (LIFO). If all allocations will be freed together, set the LIFO template parameter to false, then there is practically no memory overhead for each allocation. For a de-allocation in reverse order, set LIFO to true. Then a structure of the size of two Ints has to be added for each allocation for bookkeeping purposes.

    Template Parameters
    BLOCK_SIZEMinimum size of each memory block which is obtained from ALLOCATOR.
    LIFOUse true if you want to use this allocator in a stack-like LIFO way. This adds some overhead. If set to false, no actual de-allocation will happen until all allocations have been freed.
    ALLOCATORThe parent allocator from which this allocator shall obtain its memory.

    Classes

    struct  Header
     

    Public Member Functions

     StackBufferAllocator ()
     
     StackBufferAllocator (StackBufferAllocator &&other)
     
    void * Alloc (Int size, MAXON_SOURCE_LOCATION_DECLARATION)
     
    void Free (const void *ptr)
     
     ~StackBufferAllocator ()
     

    Static Public Member Functions

    static Bool IsCompatibleWithDefaultAllocator (void *)
     

    Private Attributes

    ALLOCATOR _allocator
     
    BaseArray< Char * > _memory
     
    Header _header
     
    Char_end
     
    Int _allocCount
     

    Constructor & Destructor Documentation

    ◆ StackBufferAllocator() [1/2]

    ◆ StackBufferAllocator() [2/2]

    StackBufferAllocator ( StackBufferAllocator< BLOCK_SIZE, LIFO, ALLOCATOR > &&  other)

    ◆ ~StackBufferAllocator()

    Member Function Documentation

    ◆ Alloc()

    void* Alloc ( Int  size,
    MAXON_SOURCE_LOCATION_DECLARATION   
    )

    ◆ Free()

    void Free ( const void *  ptr)

    ◆ IsCompatibleWithDefaultAllocator()

    static Bool IsCompatibleWithDefaultAllocator ( void *  )
    static

    Returns if a memory block allocated via this allocator can be reallocated or freed by the DefaultAllocator.

    Returns
    Always false.

    Member Data Documentation

    ◆ _allocator

    ALLOCATOR _allocator
    private

    ◆ _memory

    BaseArray<Char*> _memory
    private

    ◆ _header

    Header _header
    private

    ◆ _end

    Char* _end
    private

    ◆ _allocCount

    Int _allocCount
    private