DeepCover Embedded Security in IoT: Public-key Secured Data Paths

Dependencies:   MaximInterface

Embed: (wiki syntax)

« Back to documentation index

MemoryPoolAllocator< BaseAllocator > Class Template Reference

MemoryPoolAllocator< BaseAllocator > Class Template Reference

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

#include <allocators.h>

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 ()
 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)

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)

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 102 of file allocators.h.


Constructor & Destructor Documentation

MemoryPoolAllocator ( size_t  chunkSize = kDefaultChunkCapacity,
BaseAllocator *  baseAllocator = 0 
)

Constructor with chunkSize.

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

Definition at line 110 of file allocators.h.

MemoryPoolAllocator ( void *  buffer,
size_t  size,
size_t  chunkSize = kDefaultChunkCapacity,
BaseAllocator *  baseAllocator = 0 
)

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 125 of file allocators.h.

Destructor.

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

Definition at line 139 of file allocators.h.


Member Function Documentation

size_t Capacity (  ) const

Computes the total capacity of allocated memory chunks.

Returns:
total capacity in bytes.

Definition at line 158 of file allocators.h.

void Clear (  )

Deallocates all memory chunks, excluding the user-supplied buffer.

Definition at line 145 of file allocators.h.

static void Free ( void *  ptr ) [static]

Frees a memory block (concept Allocator)

Definition at line 225 of file allocators.h.

void* Malloc ( size_t  size )

Allocates a memory block. (concept Allocator)

Definition at line 176 of file allocators.h.

void* Realloc ( void *  originalPtr,
size_t  originalSize,
size_t  newSize 
)

Resizes a memory block (concept Allocator)

Definition at line 191 of file allocators.h.

size_t Size (  ) const

Computes the memory blocks allocated.

Returns:
total used bytes.

Definition at line 168 of file allocators.h.


Field Documentation

const bool kNeedFree = false [static]

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

Definition at line 104 of file allocators.h.