RapidJSON: rapidjson::MemoryPoolAllocator< BaseAllocator > 模板类 参考

类 | Public 成员函数 | 静态 Public 成员函数 | 静态 Public 属性 | 所有成员列表
rapidjson::MemoryPoolAllocator< BaseAllocator > 模板类 参考

Default memory allocator used by the parser and DOM. 更多...

`#include <allocators.h>`

## Public 成员函数
| 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 ()
| Destructor. 更多...
void | Clear ()
| Deallocates all memory chunks, excluding the user-supplied buffer.
size_t | Capacity () const
| Computes the total capacity of allocated memory chunks. 更多...
size_t | Size () const
| Computes the memory blocks allocated. 更多...
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)

## 静态 Public 成员函数
static void | Free (void *ptr)
| Frees a memory block (concept Allocator)

## 静态 Public 属性
static const bool | kNeedFree = false
| Tell users that no need to call Free() with this allocator. (concept Allocator)

## 详细描述

### 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.

模板参数

  BaseAllocator | the allocator type for allocating memory chunks. Default is CrtAllocator.

注解
  implements Allocator concept

## 构造及析构函数说明

## ◆ MemoryPoolAllocator() [1/2]

template<typename BaseAllocator = CrtAllocator>

rapidjson::MemoryPoolAllocator< BaseAllocator >::MemoryPoolAllocator | ( | size_t | chunkSize = `kDefaultChunkCapacity`,
|  | BaseAllocator * | baseAllocator = `0`
| ) |  |
| inline

Constructor with chunkSize.

参数

  chunkSize | The size of memory chunk. The default is kDefaultChunkSize.
  baseAllocator | The allocator for allocating memory chunks.

## ◆ MemoryPoolAllocator() [2/2]

template<typename BaseAllocator = CrtAllocator>

rapidjson::MemoryPoolAllocator< BaseAllocator >::MemoryPoolAllocator | ( | void * | 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.

参数

  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.

## ◆ ~MemoryPoolAllocator()

template<typename BaseAllocator = CrtAllocator>

rapidjson::MemoryPoolAllocator< BaseAllocator >::~MemoryPoolAllocator | ( |  | ) |
| inline

Destructor.

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

## 成员函数说明

## ◆ Capacity()

template<typename BaseAllocator = CrtAllocator>

size_t rapidjson::MemoryPoolAllocator< BaseAllocator >::Capacity | ( |  | ) | const
| inline

Computes the total capacity of allocated memory chunks.

返回
  total capacity in bytes.

## ◆ Size()

template<typename BaseAllocator = CrtAllocator>

size_t rapidjson::MemoryPoolAllocator< BaseAllocator >::Size | ( |  | ) | const
| inline

Computes the memory blocks allocated.

返回
  total used bytes.

该类的文档由以下文件生成:

- include/rapidjson/allocators.h