Torque3D Documentation / _generateds / MemoryPoolAllocator

MemoryPoolAllocator

Engine/source/persistence/rapidjson/allocators.h

Default memory allocator used by the parser and DOM.

More...

Classes:

class

Chunk header for perpending to each chunk.

Public Static Attributes

const bool

Tell users that no need to call Free() with this allocator. (concept Allocator)

Private Static Attributes

const int

Default chunk capacity.

Private Attributes

BaseAllocator *

base allocator for allocating memory chunks.

size_t

The minimum capacity of chunk when they are allocated.

ChunkHeader *

Head of the chunk linked-list. Only the head chunk serves allocation.

BaseAllocator *

base allocator created by this object.

void *

User supplied buffer.

Public Functions

MemoryPoolAllocator(size_t chunkSize, BaseAllocator * baseAllocator)

Constructor with chunkSize.

MemoryPoolAllocator(void * buffer, size_t size, size_t chunkSize, BaseAllocator * baseAllocator)

Constructor with user-supplied buffer.

Destructor.

size_t

Computes the total capacity of allocated memory chunks.

Deallocates all memory chunks, excluding the user-supplied buffer.

void *
Malloc(size_t size)

Allocates a memory block. (concept Allocator)

void *
Realloc(void * originalPtr, size_t originalSize, size_t newSize)

Resizes a memory block (concept Allocator)

size_t
Size()

Computes the memory blocks allocated.

Public Static Functions

Free(void * ptr)

Frees a memory block (concept Allocator)

Private Functions

Copy constructor is not permitted.

bool
AddChunk(size_t capacity)

Creates a new chunk.

Copy assignment operator is not permitted.

Detailed Description

Default memory allocator used by the parser and DOM.

This allocator allocate memory blocks from pre-allocated memory chunks.

It does not free memory blocks. And Realloc() only allocate new memory.

The memory chunks are allocated by BaseAllocator, which is CrtAllocator by default.

User may also supply a buffer as the first chunk.

If the user-buffer is full then additional chunks are allocated by BaseAllocator.

The user-buffer is not deallocated by this allocator.

Parameters:

BaseAllocator

the allocator type for allocating memory chunks. Default is CrtAllocator.

note:

implements Allocator concept

Public Static Attributes

const bool kNeedFree 

Tell users that no need to call Free() with this allocator. (concept Allocator)

Private Static Attributes

const int kDefaultChunkCapacity 

Default chunk capacity.

Private Attributes

BaseAllocator * baseAllocator_ 

base allocator for allocating memory chunks.

size_t chunk_capacity_ 

The minimum capacity of chunk when they are allocated.

ChunkHeader * chunkHead_ 

Head of the chunk linked-list. Only the head chunk serves allocation.

BaseAllocator * ownBaseAllocator_ 

base allocator created by this object.

void * userBuffer_ 

User supplied buffer.

Public Functions

MemoryPoolAllocator(size_t chunkSize, BaseAllocator * baseAllocator)

Constructor with chunkSize.

Parameters:

chunkSize

The size of memory chunk. The default is kDefaultChunkSize.

baseAllocator

The allocator for allocating memory chunks.

MemoryPoolAllocator(void * buffer, size_t size, size_t chunkSize, BaseAllocator * baseAllocator)

Constructor with user-supplied buffer.

The user buffer will be used firstly. When it is full, memory pool allocates new chunk with chunk size.

The user buffer will not be deallocated when this allocator is destructed.

Parameters:

buffer

User supplied buffer.

size

Size of the buffer in bytes. It must at least larger than sizeof(ChunkHeader).

chunkSize

The size of memory chunk. The default is kDefaultChunkSize.

baseAllocator

The allocator for allocating memory chunks.

~MemoryPoolAllocator()

Destructor.

This deallocates all memory chunks, excluding the user-supplied buffer.

Capacity()

Computes the total capacity of allocated memory chunks.

return:

total capacity in bytes.

Clear()

Deallocates all memory chunks, excluding the user-supplied buffer.

Malloc(size_t size)

Allocates a memory block. (concept Allocator)

Realloc(void * originalPtr, size_t originalSize, size_t newSize)

Resizes a memory block (concept Allocator)

Size()

Computes the memory blocks allocated.

return:

total used bytes.

Public Static Functions

Free(void * ptr)

Frees a memory block (concept Allocator)

Private Functions

MemoryPoolAllocator(const MemoryPoolAllocator & rhs)

Copy constructor is not permitted.

AddChunk(size_t capacity)

Creates a new chunk.

Parameters:

capacity

Capacity of the chunk in bytes.

return:

true if success.

operator=(const MemoryPoolAllocator & rhs)

Copy assignment operator is not permitted.