![]() |
|
Default memory allocator used by the parser and DOM. More...
#include <rapidjson.h>
Classes | |
struct | ChunkHeader |
Chunk header for perpending to each chunk. More... | |
Public Member Functions | |
MemoryPoolAllocator (size_t chunkSize=kDefaultChunkCapacity, BaseAllocator *baseAllocator=0) | |
Constructor with chunkSize. More... | |
MemoryPoolAllocator (char *buffer, size_t size, size_t chunkSize=kDefaultChunkCapacity, BaseAllocator *baseAllocator=0) | |
Constructor with user-supplied buffer. More... | |
~MemoryPoolAllocator () | |
Destructor. More... | |
void | Clear () |
Deallocates all memory chunks, excluding the user-supplied buffer. More... | |
size_t | Capacity () |
Computes the total capacity of allocated memory chunks. More... | |
size_t | Size () |
Computes the memory blocks allocated. More... | |
void * | Malloc (size_t size) |
Allocates a memory block. (concept Allocator) More... | |
void * | Realloc (void *originalPtr, size_t originalSize, size_t newSize) |
Resizes a memory block (concept Allocator) More... | |
Static Public Member Functions | |
static void | Free (void *) |
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 | |
void | AddChunk (size_t capacity) |
Creates a new chunk. More... | |
Private Attributes | |
ChunkHeader * | chunkHead_ |
Head of the chunk linked-list. Only the head chunk serves allocation. More... | |
size_t | chunk_capacity_ |
The minimum capacity of chunk when they are allocated. More... | |
char * | userBuffer_ |
User supplied buffer. More... | |
BaseAllocator * | baseAllocator_ |
base allocator for allocating memory chunks. More... | |
BaseAllocator * | ownBaseAllocator_ |
base allocator created by this object. 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. |
|
inline |
Constructor with chunkSize.
chunkSize | The size of memory chunk. The default is kDefaultChunkSize. |
baseAllocator | The allocator for allocating memory chunks. |
References rapidjson::MemoryPoolAllocator< BaseAllocator >::AddChunk(), rapidjson::MemoryPoolAllocator< BaseAllocator >::baseAllocator_, rapidjson::MemoryPoolAllocator< BaseAllocator >::chunk_capacity_, and rapidjson::MemoryPoolAllocator< BaseAllocator >::ownBaseAllocator_.
|
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. |
References rapidjson::MemoryPoolAllocator< BaseAllocator >::ChunkHeader::capacity, rapidjson::MemoryPoolAllocator< BaseAllocator >::chunkHead_, rapidjson::MemoryPoolAllocator< BaseAllocator >::ChunkHeader::next, RAPIDJSON_ASSERT, and rapidjson::MemoryPoolAllocator< BaseAllocator >::ChunkHeader::size.
|
inline |
Destructor.
This deallocates all memory chunks, excluding the user-supplied buffer.
References rapidjson::MemoryPoolAllocator< BaseAllocator >::Clear(), and rapidjson::MemoryPoolAllocator< BaseAllocator >::ownBaseAllocator_.
|
inlineprivate |
Creates a new chunk.
capacity | Capacity of the chunk in bytes. |
References rapidjson::MemoryPoolAllocator< BaseAllocator >::baseAllocator_, rapidjson::MemoryPoolAllocator< BaseAllocator >::ChunkHeader::capacity, rapidjson::MemoryPoolAllocator< BaseAllocator >::chunkHead_, rapidjson::MemoryPoolAllocator< BaseAllocator >::ChunkHeader::next, and rapidjson::MemoryPoolAllocator< BaseAllocator >::ChunkHeader::size.
Referenced by rapidjson::MemoryPoolAllocator< BaseAllocator >::Malloc(), and rapidjson::MemoryPoolAllocator< BaseAllocator >::MemoryPoolAllocator().
|
inline |
Computes the total capacity of allocated memory chunks.
References rapidjson::MemoryPoolAllocator< BaseAllocator >::chunkHead_, and rapidjson::MemoryPoolAllocator< BaseAllocator >::ChunkHeader::next.
|
inline |
Deallocates all memory chunks, excluding the user-supplied buffer.
References rapidjson::MemoryPoolAllocator< BaseAllocator >::baseAllocator_, rapidjson::MemoryPoolAllocator< BaseAllocator >::chunkHead_, rapidjson::MemoryPoolAllocator< BaseAllocator >::ChunkHeader::next, and rapidjson::MemoryPoolAllocator< BaseAllocator >::userBuffer_.
Referenced by rapidjson::MemoryPoolAllocator< BaseAllocator >::~MemoryPoolAllocator().
|
inlinestatic |
|
inline |
Allocates a memory block. (concept Allocator)
References rapidjson::MemoryPoolAllocator< BaseAllocator >::AddChunk(), rapidjson::MemoryPoolAllocator< BaseAllocator >::ChunkHeader::capacity, rapidjson::MemoryPoolAllocator< BaseAllocator >::chunk_capacity_, rapidjson::MemoryPoolAllocator< BaseAllocator >::chunkHead_, RAPIDJSON_ASSERT, and rapidjson::MemoryPoolAllocator< BaseAllocator >::ChunkHeader::size.
Referenced by rapidjson::MemoryPoolAllocator< BaseAllocator >::Realloc().
|
inline |
Resizes a memory block (concept Allocator)
References rapidjson::MemoryPoolAllocator< BaseAllocator >::chunkHead_, rapidjson::MemoryPoolAllocator< BaseAllocator >::Malloc(), RAPIDJSON_ASSERT, and rapidjson::MemoryPoolAllocator< BaseAllocator >::ChunkHeader::size.
|
inline |
Computes the memory blocks allocated.
References rapidjson::MemoryPoolAllocator< BaseAllocator >::chunkHead_, and rapidjson::MemoryPoolAllocator< BaseAllocator >::ChunkHeader::next.
|
private |
base allocator for allocating memory chunks.
Referenced by rapidjson::MemoryPoolAllocator< BaseAllocator >::AddChunk(), rapidjson::MemoryPoolAllocator< BaseAllocator >::Clear(), and rapidjson::MemoryPoolAllocator< BaseAllocator >::MemoryPoolAllocator().
|
private |
The minimum capacity of chunk when they are allocated.
Referenced by rapidjson::MemoryPoolAllocator< BaseAllocator >::Malloc(), and rapidjson::MemoryPoolAllocator< BaseAllocator >::MemoryPoolAllocator().
|
private |
Head of the chunk linked-list. Only the head chunk serves allocation.
Referenced by rapidjson::MemoryPoolAllocator< BaseAllocator >::AddChunk(), rapidjson::MemoryPoolAllocator< BaseAllocator >::Capacity(), rapidjson::MemoryPoolAllocator< BaseAllocator >::Clear(), rapidjson::MemoryPoolAllocator< BaseAllocator >::Malloc(), rapidjson::MemoryPoolAllocator< BaseAllocator >::MemoryPoolAllocator(), rapidjson::MemoryPoolAllocator< BaseAllocator >::Realloc(), and rapidjson::MemoryPoolAllocator< BaseAllocator >::Size().
|
staticprivate |
Default chunk capacity.
|
static |
Tell users that no need to call Free() with this allocator. (concept Allocator)
|
private |
base allocator created by this object.
Referenced by rapidjson::MemoryPoolAllocator< BaseAllocator >::MemoryPoolAllocator(), and rapidjson::MemoryPoolAllocator< BaseAllocator >::~MemoryPoolAllocator().
|
private |
User supplied buffer.
Referenced by rapidjson::MemoryPoolAllocator< BaseAllocator >::Clear().