15 #ifndef RAPIDJSON_ALLOCATORS_H_
16 #define RAPIDJSON_ALLOCATORS_H_
67 return std::malloc(size);
71 void*
Realloc(
void* originalPtr,
size_t originalSize,
size_t newSize) {
74 std::free(originalPtr);
77 return std::realloc(originalPtr, newSize);
79 static void Free(
void *ptr) { std::free(ptr); }
101 template <
typename BaseAllocator = CrtAllocator>
161 capacity += c->capacity;
190 void*
Realloc(
void* originalPtr,
size_t originalSize,
size_t newSize) {
191 if (originalPtr == 0)
198 if (originalSize >= newSize)
203 size_t increment =
static_cast<size_t>(newSize - originalSize);
212 void* newBuffer =
Malloc(newSize);
215 std::memcpy(newBuffer, originalPtr, originalSize);
220 static void Free(
void *ptr) { (void)ptr; }
261 #endif // RAPIDJSON_ENCODINGS_H_
size_t Capacity() const
Computes the total capacity of allocated memory chunks.
Definition: allocators.h:158
BaseAllocator * ownBaseAllocator_
base allocator created by this object.
Definition: allocators.h:256
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:344
void * Malloc(size_t size)
Allocates a memory block. (concept Allocator)
Definition: allocators.h:176
void * userBuffer_
User supplied buffer.
Definition: allocators.h:254
static const int kDefaultChunkCapacity
Default chunk capacity.
Definition: allocators.h:241
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition: rapidjson.h:119
void * Malloc(size_t size)
Definition: allocators.h:65
int next(int i, int n)
Definition: RecastContour.cpp:469
size_t Size() const
Computes the memory blocks allocated.
Definition: allocators.h:168
arena_t NULL
Definition: jemalloc_internal.h:624
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition: rapidjson.h:116
void Clear()
Deallocates all memory chunks, excluding the user-supplied buffer.
Definition: allocators.h:145
ChunkHeader * chunkHead_
Head of the chunk linked-list. Only the head chunk serves allocation.
Definition: allocators.h:252
void * Realloc(void *originalPtr, size_t originalSize, size_t newSize)
Definition: allocators.h:71
#define RAPIDJSON_NEW(x)
! customization point for global new
Definition: rapidjson.h:480
MemoryPoolAllocator & operator=(const MemoryPoolAllocator &rhs)
Copy assignment operator is not permitted.
#define RAPIDJSON_DELETE(x)
! customization point for global delete
Definition: rapidjson.h:484
BaseAllocator * baseAllocator_
base allocator for allocating memory chunks.
Definition: allocators.h:255
void AddChunk(size_t capacity)
Creates a new chunk.
Definition: allocators.h:231
void * Realloc(void *originalPtr, size_t originalSize, size_t newSize)
Resizes a memory block (concept Allocator)
Definition: allocators.h:190
C-runtime library allocator.
Definition: allocators.h:62
common definitions and configuration
static void Free(void *ptr)
Definition: allocators.h:79
size_t chunk_capacity_
The minimum capacity of chunk when they are allocated.
Definition: allocators.h:253
static void Free(void *ptr)
Frees a memory block (concept Allocator)
Definition: allocators.h:220
static const bool kNeedFree
Definition: allocators.h:64
#define RAPIDJSON_ALIGN(x)
Data alignment of the machine.
Definition: rapidjson.h:247
MemoryPoolAllocator(size_t chunkSize=kDefaultChunkCapacity, BaseAllocator *baseAllocator=0)
Constructor with chunkSize.
Definition: allocators.h:110
static const bool kNeedFree
Tell users that no need to call Free() with this allocator. (concept Allocator)
Definition: allocators.h:104
MemoryPoolAllocator(void *buffer, size_t size, size_t chunkSize=kDefaultChunkCapacity, BaseAllocator *baseAllocator=0)
Constructor with user-supplied buffer.
Definition: allocators.h:125
Default memory allocator used by the parser and DOM.
Definition: allocators.h:102
~MemoryPoolAllocator()
Destructor.
Definition: allocators.h:139