15 #ifndef CEREAL_RAPIDJSON_ALLOCATORS_H_
16 #define CEREAL_RAPIDJSON_ALLOCATORS_H_
63 #ifndef CEREAL_RAPIDJSON_ALLOCATOR_DEFAULT_CHUNK_CAPACITY
64 #define CEREAL_RAPIDJSON_ALLOCATOR_DEFAULT_CHUNK_CAPACITY (64 * 1024)
80 return std::malloc(size);
84 void*
Realloc(
void* originalPtr,
size_t originalSize,
size_t newSize) {
87 std::free(originalPtr);
90 return std::realloc(originalPtr, newSize);
92 static void Free(
void *ptr) { std::free(ptr); }
114 template <
typename BaseAllocator = CrtAllocator>
174 capacity += c->capacity;
204 void*
Realloc(
void* originalPtr,
size_t originalSize,
size_t newSize) {
205 if (originalPtr == 0)
215 if (originalSize >= newSize)
220 size_t increment =
static_cast<size_t>(newSize - originalSize);
228 if (
void* newBuffer =
Malloc(newSize)) {
230 std::memcpy(newBuffer, originalPtr, originalSize);
238 static void Free(
void *ptr) { (void)ptr; }
254 chunk->capacity = capacity;
#define CEREAL_RAPIDJSON_ASSERT(x)
Definition: json.hpp:50
C-runtime library allocator.
Definition: allocators.h:75
static void Free(void *ptr)
Definition: allocators.h:92
void * Realloc(void *originalPtr, size_t originalSize, size_t newSize)
Definition: allocators.h:84
static const bool kNeedFree
Definition: allocators.h:77
void * Malloc(size_t size)
Definition: allocators.h:78
Default memory allocator used by the parser and DOM.
Definition: allocators.h:115
void * Malloc(size_t size)
Allocates a memory block. (concept Allocator)
Definition: allocators.h:189
MemoryPoolAllocator & operator=(const MemoryPoolAllocator &rhs)
Copy assignment operator is not permitted.
MemoryPoolAllocator(void *buffer, size_t size, size_t chunkSize=kDefaultChunkCapacity, BaseAllocator *baseAllocator=0)
Constructor with user-supplied buffer.
Definition: allocators.h:138
BaseAllocator * ownBaseAllocator_
base allocator created by this object.
Definition: allocators.h:279
bool AddChunk(size_t capacity)
Creates a new chunk.
Definition: allocators.h:250
size_t Capacity() const
Computes the total capacity of allocated memory chunks.
Definition: allocators.h:171
ChunkHeader * chunkHead_
Head of the chunk linked-list. Only the head chunk serves allocation.
Definition: allocators.h:275
void Clear()
Deallocates all memory chunks, excluding the user-supplied buffer.
Definition: allocators.h:158
BaseAllocator * baseAllocator_
base allocator for allocating memory chunks.
Definition: allocators.h:278
size_t chunk_capacity_
The minimum capacity of chunk when they are allocated.
Definition: allocators.h:276
static void Free(void *ptr)
Frees a memory block (concept Allocator)
Definition: allocators.h:238
MemoryPoolAllocator(const MemoryPoolAllocator &rhs)
Copy constructor is not permitted.
void * userBuffer_
User supplied buffer.
Definition: allocators.h:277
static const int kDefaultChunkCapacity
Default chunk capacity.
Definition: allocators.h:264
static const bool kNeedFree
Tell users that no need to call Free() with this allocator. (concept Allocator)
Definition: allocators.h:117
void * Realloc(void *originalPtr, size_t originalSize, size_t newSize)
Resizes a memory block (concept Allocator)
Definition: allocators.h:204
~MemoryPoolAllocator()
Destructor.
Definition: allocators.h:152
size_t Size() const
Computes the memory blocks allocated.
Definition: allocators.h:181
MemoryPoolAllocator(size_t chunkSize=kDefaultChunkCapacity, BaseAllocator *baseAllocator=0)
Constructor with chunkSize.
Definition: allocators.h:123
#define CEREAL_RAPIDJSON_ALIGN(x)
Data alignment of the machine.
Definition: rapidjson.h:276
#define CEREAL_RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition: rapidjson.h:121
#define CEREAL_RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition: rapidjson.h:124
#define CEREAL_RAPIDJSON_ALLOCATOR_DEFAULT_CHUNK_CAPACITY
User-defined kDefaultChunkCapacity definition.
Definition: allocators.h:64
common definitions and configuration
#define CEREAL_RAPIDJSON_DELETE(x)
! customization point for global delete
Definition: rapidjson.h:631
#define CEREAL_RAPIDJSON_NEW(TypeName)
! customization point for global new
Definition: rapidjson.h:627