Default memory allocator used by the parser and DOM. More...
#include <allocators.h>
Classes | |
struct | ChunkHeader |
Chunk header for perpending to each chunk. More... | |
Public Member Functions | |
size_t | Capacity () const |
Computes the total capacity of allocated memory chunks. More... | |
void | Clear () |
Deallocates all memory chunks, excluding the user-supplied buffer. More... | |
void * | Malloc (size_t size) |
Allocates a memory block. (concept Allocator) More... | |
MemoryPoolAllocator (size_t chunkSize=kDefaultChunkCapacity, BaseAllocator *baseAllocator=0) | |
Constructor with chunkSize. More... | |
MemoryPoolAllocator (void *buffer, size_t size, size_t chunkSize=kDefaultChunkCapacity, BaseAllocator *baseAllocator=0) | |
Constructor with user-supplied buffer. More... | |
void * | Realloc (void *originalPtr, size_t originalSize, size_t newSize) |
Resizes a memory block (concept Allocator) More... | |
size_t | Size () const |
Computes the memory blocks allocated. More... | |
~MemoryPoolAllocator () | |
Destructor. More... | |
Static Public Member Functions | |
static void | Free (void *ptr) |
Frees a memory block (concept Allocator) More... | |
Static Public Attributes | |
static const bool | kNeedFree = false |
Tell users that no need to call Free() with this allocator. (concept Allocator) More... | |
Private Member Functions | |
bool | AddChunk (size_t capacity) |
Creates a new chunk. More... | |
MemoryPoolAllocator (const MemoryPoolAllocator &rhs) | |
Copy constructor is not permitted. More... | |
MemoryPoolAllocator & | operator= (const MemoryPoolAllocator &rhs) |
Copy assignment operator is not permitted. More... | |
Private Attributes | |
BaseAllocator * | baseAllocator_ |
base allocator for allocating memory chunks. More... | |
size_t | chunk_capacity_ |
The minimum capacity of chunk when they are allocated. More... | |
ChunkHeader * | chunkHead_ |
Head of the chunk linked-list. Only the head chunk serves allocation. More... | |
BaseAllocator * | ownBaseAllocator_ |
base allocator created by this object. More... | |
void * | userBuffer_ |
User supplied buffer. More... | |
Static Private Attributes | |
static const int | kDefaultChunkCapacity = 64 * 1024 |
Default chunk capacity. More... | |
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.
BaseAllocator | the allocator type for allocating memory chunks. Default is CrtAllocator. |
Definition at line 102 of file allocators.h.
|
inline |
Constructor with chunkSize.
chunkSize | The size of memory chunk. The default is kDefaultChunkSize. |
baseAllocator | The allocator for allocating memory chunks. |
Definition at line 110 of file allocators.h.
|
inline |
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.
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. |
Definition at line 125 of file allocators.h.
|
inline |
Destructor.
This deallocates all memory chunks, excluding the user-supplied buffer.
Definition at line 139 of file allocators.h.
|
private |
Copy constructor is not permitted.
|
inlineprivate |
Creates a new chunk.
capacity | Capacity of the chunk in bytes. |
Definition at line 237 of file allocators.h.
|
inline |
Computes the total capacity of allocated memory chunks.
Definition at line 158 of file allocators.h.
|
inline |
Deallocates all memory chunks, excluding the user-supplied buffer.
Definition at line 145 of file allocators.h.
|
inlinestatic |
Frees a memory block (concept Allocator)
Definition at line 225 of file allocators.h.
|
inline |
Allocates a memory block. (concept Allocator)
Definition at line 176 of file allocators.h.
|
private |
Copy assignment operator is not permitted.
|
inline |
Resizes a memory block (concept Allocator)
Definition at line 191 of file allocators.h.
|
inline |
Computes the memory blocks allocated.
Definition at line 168 of file allocators.h.
|
private |
base allocator for allocating memory chunks.
Definition at line 265 of file allocators.h.
|
private |
The minimum capacity of chunk when they are allocated.
Definition at line 263 of file allocators.h.
|
private |
Head of the chunk linked-list. Only the head chunk serves allocation.
Definition at line 262 of file allocators.h.
|
staticprivate |
Default chunk capacity.
Definition at line 251 of file allocators.h.
|
static |
Tell users that no need to call Free() with this allocator. (concept Allocator)
Definition at line 104 of file allocators.h.
|
private |
base allocator created by this object.
Definition at line 266 of file allocators.h.
|
private |
User supplied buffer.
Definition at line 264 of file allocators.h.