Default memory allocator used by the parser and DOM. More...
Classes | |
| struct | ChunkHeader |
| Chunk header for perpending to each chunk. More... | |
| struct | SharedData |
Public Member Functions | |
| MemoryPoolAllocator (size_t chunkSize=kDefaultChunkCapacity, BaseAllocator *baseAllocator=0) | |
| Constructor with chunkSize. | |
| MemoryPoolAllocator (void *buffer, size_t size, size_t chunkSize=kDefaultChunkCapacity, BaseAllocator *baseAllocator=0) | |
| Constructor with user-supplied buffer. | |
| MemoryPoolAllocator (const MemoryPoolAllocator &rhs) RAPIDJSON_NOEXCEPT | |
| MemoryPoolAllocator & | operator= (const MemoryPoolAllocator &rhs) RAPIDJSON_NOEXCEPT |
| ~MemoryPoolAllocator () RAPIDJSON_NOEXCEPT | |
| Destructor. | |
| void | Clear () RAPIDJSON_NOEXCEPT |
| Deallocates all memory chunks, excluding the first/user one. | |
| size_t | Capacity () const RAPIDJSON_NOEXCEPT |
| Computes the total capacity of allocated memory chunks. | |
| size_t | Size () const RAPIDJSON_NOEXCEPT |
| Computes the memory blocks allocated. | |
| bool | Shared () const RAPIDJSON_NOEXCEPT |
| Whether the allocator is shared. | |
| 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). | |
| bool | operator== (const MemoryPoolAllocator &rhs) const RAPIDJSON_NOEXCEPT |
| Compare (equality) with another MemoryPoolAllocator. | |
| bool | operator!= (const MemoryPoolAllocator &rhs) const RAPIDJSON_NOEXCEPT |
| Compare (inequality) with another MemoryPoolAllocator. | |
Static Public Member Functions | |
| static void | Free (void *ptr) RAPIDJSON_NOEXCEPT |
| Frees a memory block (concept Allocator). | |
Static Public Attributes | |
| static const bool | kNeedFree = false |
| Tell users that no need to call Free() with this allocator. (concept Allocator). | |
| static const bool | kRefCounted = true |
| Tell users that this allocator is reference counted on copy. | |
Private Member Functions | |
| bool | AddChunk (size_t capacity) |
| Creates a new chunk. | |
Static Private Member Functions | |
| static ChunkHeader * | GetChunkHead (SharedData *shared) |
| static uint8_t * | GetChunkBuffer (SharedData *shared) |
| static void * | AlignBuffer (void *buf, size_t &size) |
Private Attributes | |
| size_t | chunk_capacity_ |
| The minimum capacity of chunk when they are allocated. | |
| BaseAllocator * | baseAllocator_ |
| base allocator for allocating memory chunks. | |
| SharedData * | shared_ |
| The shared data of the allocator. | |
Static Private Attributes | |
| static const size_t | SIZEOF_SHARED_DATA = RAPIDJSON_ALIGN(sizeof(SharedData)) |
| static const size_t | SIZEOF_CHUNK_HEADER = RAPIDJSON_ALIGN(sizeof(ChunkHeader)) |
| static const size_t | kDefaultChunkCapacity = RAPIDJSON_ALLOCATOR_DEFAULT_CHUNK_CAPACITY |
| Default chunk capacity. | |
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 131 of file allocators.h.
|
inlineexplicit |
Constructor with chunkSize.
| chunkSize | The size of memory chunk. The default is kDefaultChunkSize. |
| baseAllocator | The allocator for allocating memory chunks. |
Definition at line 171 of file allocators.h.
References baseAllocator_, chunk_capacity_, kDefaultChunkCapacity, Malloc(), RAPIDJSON_ASSERT, RAPIDJSON_NEW, and shared_.
Referenced by operator!=(), and operator==().
|
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 202 of file allocators.h.
References baseAllocator_, chunk_capacity_, kDefaultChunkCapacity, RAPIDJSON_ASSERT, and shared_.
|
inline |
Definition at line 217 of file allocators.h.
|
inline |
Destructor.
This deallocates all memory chunks, excluding the user-supplied buffer.
Definition at line 260 of file allocators.h.
References baseAllocator_, Clear(), RAPIDJSON_DELETE, and shared_.
|
inlineprivate |
Creates a new chunk.
| capacity | Capacity of the chunk in bytes. |
Definition at line 391 of file allocators.h.
References baseAllocator_, RAPIDJSON_NEW, and shared_.
Referenced by Malloc().
|
inlinestaticprivate |
Definition at line 405 of file allocators.h.
|
inline |
Computes the total capacity of allocated memory chunks.
Definition at line 294 of file allocators.h.
References RAPIDJSON_NOEXCEPT_ASSERT, and shared_.
|
inline |
Deallocates all memory chunks, excluding the first/user one.
Definition at line 278 of file allocators.h.
References baseAllocator_, MemoryPoolAllocator< BaseAllocator >::ChunkHeader::next, RAPIDJSON_NOEXCEPT_ASSERT, and shared_.
Referenced by ~MemoryPoolAllocator().
|
inlinestatic |
Frees a memory block (concept Allocator).
Definition at line 373 of file allocators.h.
|
inlinestaticprivate |
Definition at line 155 of file allocators.h.
|
inlinestaticprivate |
Definition at line 151 of file allocators.h.
|
inline |
Allocates a memory block. (concept Allocator).
Definition at line 322 of file allocators.h.
References AddChunk(), chunk_capacity_, RAPIDJSON_ALIGN, RAPIDJSON_NOEXCEPT_ASSERT, RAPIDJSON_UNLIKELY, and shared_.
Referenced by MemoryPoolAllocator(), and Realloc().
|
inline |
Compare (inequality) with another MemoryPoolAllocator.
Definition at line 382 of file allocators.h.
References MemoryPoolAllocator(), and operator==().
|
inline |
Definition at line 225 of file allocators.h.
|
inline |
Compare (equality) with another MemoryPoolAllocator.
Definition at line 376 of file allocators.h.
References MemoryPoolAllocator(), RAPIDJSON_NOEXCEPT_ASSERT, and shared_.
Referenced by operator!=().
|
inline |
Resizes a memory block (concept Allocator).
Definition at line 338 of file allocators.h.
References Malloc(), RAPIDJSON_ALIGN, RAPIDJSON_NOEXCEPT_ASSERT, and shared_.
|
inline |
Whether the allocator is shared.
Definition at line 316 of file allocators.h.
References RAPIDJSON_NOEXCEPT_ASSERT, and shared_.
|
inline |
Computes the memory blocks allocated.
Definition at line 305 of file allocators.h.
References RAPIDJSON_NOEXCEPT_ASSERT, and shared_.
|
private |
base allocator for allocating memory chunks.
Definition at line 420 of file allocators.h.
Referenced by AddChunk(), Clear(), MemoryPoolAllocator(), MemoryPoolAllocator(), and ~MemoryPoolAllocator().
|
private |
The minimum capacity of chunk when they are allocated.
Definition at line 419 of file allocators.h.
Referenced by Malloc(), MemoryPoolAllocator(), and MemoryPoolAllocator().
|
staticprivate |
Default chunk capacity.
Definition at line 160 of file allocators.h.
Referenced by MemoryPoolAllocator(), and MemoryPoolAllocator().
|
static |
Tell users that no need to call Free() with this allocator. (concept Allocator).
Definition at line 163 of file allocators.h.
|
static |
Tell users that this allocator is reference counted on copy.
Definition at line 164 of file allocators.h.
|
private |
The shared data of the allocator.
Definition at line 421 of file allocators.h.
Referenced by AddChunk(), Capacity(), Clear(), Malloc(), MemoryPoolAllocator(), MemoryPoolAllocator(), operator==(), Realloc(), Shared(), Size(), and ~MemoryPoolAllocator().
|
staticprivate |
Definition at line 149 of file allocators.h.
|
staticprivate |
Definition at line 148 of file allocators.h.