Default memory allocator used by the parser and DOM. More...

#include <allocators.h>

Inheritance diagram for rapidjson::MemoryPoolAllocator< BaseAllocator >:
[legend]
Collaboration diagram for rapidjson::MemoryPoolAllocator< BaseAllocator >:
[legend]

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.
 
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)
 
void * Realloc (void *originalPtr, size_t originalSize, size_t newSize)
 Resizes a memory block (concept Allocator)
 

Static Public Member Functions

static void Free (void *ptr)
 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)
 

Private Member Functions

void AddChunk (size_t capacity)
 Creates a new chunk. More...
 

Private Attributes

ChunkHeaderchunkHead_
 Head of the chunk linked-list. Only the head chunk serves allocation.
 
size_t chunk_capacity_
 The minimum capacity of chunk when they are allocated.
 
char * userBuffer_
 User supplied buffer.
 
BaseAllocator * baseAllocator_
 base allocator for allocating memory chunks.
 
BaseAllocator * ownBaseAllocator_
 base allocator created by this object.
 

Static Private Attributes

static const int kDefaultChunkCapacity = 64 * 1024
 Default chunk capacity.
 

Detailed Description

template<typename BaseAllocator = CrtAllocator>
class rapidjson::MemoryPoolAllocator< BaseAllocator >

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.

Template Parameters
BaseAllocatorthe allocator type for allocating memory chunks. Default is CrtAllocator.

Constructor & Destructor Documentation

template<typename BaseAllocator = CrtAllocator>
rapidjson::MemoryPoolAllocator< BaseAllocator >::MemoryPoolAllocator ( size_t  chunkSize = kDefaultChunkCapacity,
BaseAllocator *  baseAllocator = 0 
)
inline

Constructor with chunkSize.

Parameters
chunkSizeThe size of memory chunk. The default is kDefaultChunkSize.
baseAllocatorThe allocator for allocating memory chunks.

Here is the call graph for this function:

template<typename BaseAllocator = CrtAllocator>
rapidjson::MemoryPoolAllocator< BaseAllocator >::MemoryPoolAllocator ( char *  buffer,
size_t  size,
size_t  chunkSize = kDefaultChunkCapacity,
BaseAllocator *  baseAllocator = 0 
)
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.
Parameters
bufferUser supplied buffer.
sizeSize of the buffer in bytes. It must at least larger than sizeof(ChunkHeader).
chunkSizeThe size of memory chunk. The default is kDefaultChunkSize.
baseAllocatorThe allocator for allocating memory chunks.
template<typename BaseAllocator = CrtAllocator>
rapidjson::MemoryPoolAllocator< BaseAllocator >::~MemoryPoolAllocator ( )
inline

Destructor.

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

Here is the call graph for this function:

Member Function Documentation

template<typename BaseAllocator = CrtAllocator>
void rapidjson::MemoryPoolAllocator< BaseAllocator >::AddChunk ( size_t  capacity)
inlineprivate

Creates a new chunk.

Parameters
capacityCapacity of the chunk in bytes.

Here is the caller graph for this function:

template<typename BaseAllocator = CrtAllocator>
size_t rapidjson::MemoryPoolAllocator< BaseAllocator >::Capacity ( )
inline

Computes the total capacity of allocated memory chunks.

Returns
total capacity in bytes.
template<typename BaseAllocator = CrtAllocator>
size_t rapidjson::MemoryPoolAllocator< BaseAllocator >::Size ( )
inline

Computes the memory blocks allocated.

Returns
total used bytes.

The documentation for this class was generated from the following file:
  • /home/travis/build/urho3d/Urho3D/Source/ThirdParty/rapidjson/include/rapidjson/allocators.h