Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
MemoryPoolAllocator< BaseAllocator > Class Template Reference

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

#include </__w/arcaneframework.github.io/arcaneframework.github.io/framework/arccore/src/common/arccore/common/internal/json/rapidjson/allocators.h>

Collaboration diagram for MemoryPoolAllocator< BaseAllocator >:

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
MemoryPoolAllocatoroperator= (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 ChunkHeaderGetChunkHead (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.
SharedDatashared_
 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.

Detailed Description

template<typename BaseAllocator = CrtAllocator>
class 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.
Note
implements Allocator concept

Definition at line 131 of file allocators.h.

Constructor & Destructor Documentation

◆ MemoryPoolAllocator() [1/3]

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

Constructor with chunkSize.

Parameters
chunkSizeThe size of memory chunk. The default is kDefaultChunkSize.
baseAllocatorThe 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==().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MemoryPoolAllocator() [2/3]

template<typename BaseAllocator = CrtAllocator>
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.

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.

Definition at line 202 of file allocators.h.

References baseAllocator_, chunk_capacity_, kDefaultChunkCapacity, RAPIDJSON_ASSERT, and shared_.

◆ MemoryPoolAllocator() [3/3]

template<typename BaseAllocator = CrtAllocator>
MemoryPoolAllocator< BaseAllocator >::MemoryPoolAllocator ( const MemoryPoolAllocator< BaseAllocator > & rhs)
inline

Definition at line 217 of file allocators.h.

◆ ~MemoryPoolAllocator()

template<typename BaseAllocator = CrtAllocator>
MemoryPoolAllocator< BaseAllocator >::~MemoryPoolAllocator ( )
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_.

Here is the call graph for this function:

Member Function Documentation

◆ AddChunk()

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

Creates a new chunk.

Parameters
capacityCapacity of the chunk in bytes.
Returns
true if success.

Definition at line 391 of file allocators.h.

References baseAllocator_, RAPIDJSON_NEW, and shared_.

Referenced by Malloc().

Here is the caller graph for this function:

◆ AlignBuffer()

template<typename BaseAllocator = CrtAllocator>
void * MemoryPoolAllocator< BaseAllocator >::AlignBuffer ( void * buf,
size_t & size )
inlinestaticprivate

Definition at line 405 of file allocators.h.

◆ Capacity()

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

Computes the total capacity of allocated memory chunks.

Returns
total capacity in bytes.

Definition at line 294 of file allocators.h.

References RAPIDJSON_NOEXCEPT_ASSERT, and shared_.

◆ Clear()

template<typename BaseAllocator = CrtAllocator>
void MemoryPoolAllocator< BaseAllocator >::Clear ( )
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().

Here is the caller graph for this function:

◆ Free()

template<typename BaseAllocator = CrtAllocator>
void MemoryPoolAllocator< BaseAllocator >::Free ( void * ptr)
inlinestatic

Frees a memory block (concept Allocator).

Definition at line 373 of file allocators.h.

◆ GetChunkBuffer()

template<typename BaseAllocator = CrtAllocator>
uint8_t * MemoryPoolAllocator< BaseAllocator >::GetChunkBuffer ( SharedData * shared)
inlinestaticprivate

Definition at line 155 of file allocators.h.

◆ GetChunkHead()

template<typename BaseAllocator = CrtAllocator>
ChunkHeader * MemoryPoolAllocator< BaseAllocator >::GetChunkHead ( SharedData * shared)
inlinestaticprivate

Definition at line 151 of file allocators.h.

◆ Malloc()

template<typename BaseAllocator = CrtAllocator>
void * MemoryPoolAllocator< BaseAllocator >::Malloc ( size_t size)
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator!=()

template<typename BaseAllocator = CrtAllocator>
bool MemoryPoolAllocator< BaseAllocator >::operator!= ( const MemoryPoolAllocator< BaseAllocator > & rhs) const
inline

Compare (inequality) with another MemoryPoolAllocator.

Definition at line 382 of file allocators.h.

References MemoryPoolAllocator(), and operator==().

Here is the call graph for this function:

◆ operator=()

template<typename BaseAllocator = CrtAllocator>
MemoryPoolAllocator & MemoryPoolAllocator< BaseAllocator >::operator= ( const MemoryPoolAllocator< BaseAllocator > & rhs)
inline

Definition at line 225 of file allocators.h.

◆ operator==()

template<typename BaseAllocator = CrtAllocator>
bool MemoryPoolAllocator< BaseAllocator >::operator== ( const MemoryPoolAllocator< BaseAllocator > & rhs) const
inline

Compare (equality) with another MemoryPoolAllocator.

Definition at line 376 of file allocators.h.

References MemoryPoolAllocator(), RAPIDJSON_NOEXCEPT_ASSERT, and shared_.

Referenced by operator!=().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Realloc()

template<typename BaseAllocator = CrtAllocator>
void * MemoryPoolAllocator< BaseAllocator >::Realloc ( void * originalPtr,
size_t originalSize,
size_t newSize )
inline

Resizes a memory block (concept Allocator).

Definition at line 338 of file allocators.h.

References Malloc(), RAPIDJSON_ALIGN, RAPIDJSON_NOEXCEPT_ASSERT, and shared_.

Here is the call graph for this function:

◆ Shared()

template<typename BaseAllocator = CrtAllocator>
bool MemoryPoolAllocator< BaseAllocator >::Shared ( ) const
inline

Whether the allocator is shared.

Returns
true or false.

Definition at line 316 of file allocators.h.

References RAPIDJSON_NOEXCEPT_ASSERT, and shared_.

◆ Size()

template<typename BaseAllocator = CrtAllocator>
size_t MemoryPoolAllocator< BaseAllocator >::Size ( ) const
inline

Computes the memory blocks allocated.

Returns
total used bytes.

Definition at line 305 of file allocators.h.

References RAPIDJSON_NOEXCEPT_ASSERT, and shared_.

Member Data Documentation

◆ baseAllocator_

template<typename BaseAllocator = CrtAllocator>
BaseAllocator* MemoryPoolAllocator< BaseAllocator >::baseAllocator_
private

base allocator for allocating memory chunks.

Definition at line 420 of file allocators.h.

Referenced by AddChunk(), Clear(), MemoryPoolAllocator(), MemoryPoolAllocator(), and ~MemoryPoolAllocator().

◆ chunk_capacity_

template<typename BaseAllocator = CrtAllocator>
size_t MemoryPoolAllocator< BaseAllocator >::chunk_capacity_
private

The minimum capacity of chunk when they are allocated.

Definition at line 419 of file allocators.h.

Referenced by Malloc(), MemoryPoolAllocator(), and MemoryPoolAllocator().

◆ kDefaultChunkCapacity

template<typename BaseAllocator = CrtAllocator>
const size_t MemoryPoolAllocator< BaseAllocator >::kDefaultChunkCapacity = RAPIDJSON_ALLOCATOR_DEFAULT_CHUNK_CAPACITY
staticprivate

Default chunk capacity.

Definition at line 160 of file allocators.h.

Referenced by MemoryPoolAllocator(), and MemoryPoolAllocator().

◆ kNeedFree

template<typename BaseAllocator = CrtAllocator>
const bool MemoryPoolAllocator< BaseAllocator >::kNeedFree = false
static

Tell users that no need to call Free() with this allocator. (concept Allocator).

Definition at line 163 of file allocators.h.

◆ kRefCounted

template<typename BaseAllocator = CrtAllocator>
const bool MemoryPoolAllocator< BaseAllocator >::kRefCounted = true
static

Tell users that this allocator is reference counted on copy.

Definition at line 164 of file allocators.h.

◆ shared_

template<typename BaseAllocator = CrtAllocator>
SharedData* MemoryPoolAllocator< BaseAllocator >::shared_
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().

◆ SIZEOF_CHUNK_HEADER

template<typename BaseAllocator = CrtAllocator>
const size_t MemoryPoolAllocator< BaseAllocator >::SIZEOF_CHUNK_HEADER = RAPIDJSON_ALIGN(sizeof(ChunkHeader))
staticprivate

Definition at line 149 of file allocators.h.

◆ SIZEOF_SHARED_DATA

template<typename BaseAllocator = CrtAllocator>
const size_t MemoryPoolAllocator< BaseAllocator >::SIZEOF_SHARED_DATA = RAPIDJSON_ALIGN(sizeof(SharedData))
staticprivate

Definition at line 148 of file allocators.h.


The documentation for this class was generated from the following file: