|
CookMem 1.4.0
A C++ memory context / allocator
|
#include <context.h>

Public Types | |
| typedef MemContext< Arena, Logger, TreeType, T > | MemCtx |
| typedef MemPool< Arena, Logger, TreeType, T > | Pool |
| typedef Pool::size_type | size_type |
| typedef Pool::difference_type | difference_type |
| typedef Pool::value_type | value_type |
| typedef Pool::pointer | pointer |
| typedef Pool::const_pointer | const_pointer |
A basic memory context that creates a MemPool based on the arena and logger references user passed in.
This class is mostly used in cases when arena or logger that do not have default constructors.
const pointer type
pointer difference type
| typedef MemContext<Arena, Logger, TreeType, T> cookmem::MemContext< Arena, Logger, TreeType, T >::MemCtx |
The type of this memory context.
The type of the memory pool that does the actual work.
| typedef Pool::size_type cookmem::MemContext< Arena, Logger, TreeType, T >::size_type |
size type
|
inline |
Constructor.
| arena | the arena to obtain memory segments from. It must outlive this context. |
| logger | the logger for memory activities. It must outlive this context. |
| paddingSize | the number of padding bytes (0 to MAX_PADDING_SIZE) added after each allocation to detect out-of-bounds writes. |
Create a new, empty memory context that shares the arena and the logger of another context and uses the same padding size. No memory is copied.
| other | the context whose arena and logger are shared. |
Allocate memory from the memory context.
| size | memory request size. |
|
inline |
Allocate memory with an alignment larger than ALLOCATION_ALIGNMENT.
The memory is freed with deallocate () like any other allocation. reallocate () does not keep the alignment if it moves the memory.
| size | memory request size. |
| alignment | the alignment of the returned pointer. It must be a power of
|
|
inline |
Allocate n items of certain size. The memory allocated is zeroed.
| num | number of elements |
| size | element size |
|
inline |
Check if a pointer is within the address space of segments owned by this MemPool.
| ptr | memory pointer |
| checkUsed | check the pointer if it is used. |
|
inline |
Free a piece of memory previously allocated by this memory pool.
| ptr | a piece of memory to be freed. |
| size | mostly ignored. It is only used by the memory logger. |
Get the underlying memory arena.
Get the current memory footprint.
Get the memory footprint limit.
|
inline |
Get the size at which freed allocations release their memory right away.
Get the underlying logger.
Get the maximum memory footprint.
|
inline |
Get the padding byte.
|
inline |
Get the number of padding bytes checked after each allocation.
Get the underlying memory pool.
Gets the allocated size for a pointer.
If we are storing the exact size of the pointer, then the result can match the exact size of user's allocation.
Otherwise, the result is the aligned size.
| ptr | A pointer. |
|
inline |
Get the number of deallocations between empty-segment trimming passes.
Check whether or not we are padding bytes at the end of the allocated memory.
Check whether or not we are storing the exact user size in the memory.
|
inline |
This function reallocate a memory.
| ptr | the current memory pointer. |
| size | the new size |
Release all the memory segments held by this MemPool.
Release all the memory segments held by this MemPool, then the segments cached by the arena, so that the memory is returned to the system. Every pointer allocated from this context becomes invalid.
Unlike releaseAll (), this also empties the cache of a CachedArena, including the segments that other contexts sharing the arena could have reused.
|
inline |
Set the maximum memory footprint limit. Allocations that would need new memory segments beyond this limit fail and return nullptr.
| footprintLimit | the maximum total size of the memory segments in bytes. 0 means no limit. |
|
inline |
Set the size at which freed allocations release their memory right away.
A large allocation usually gets a segment of its own. When an allocation at least this large is freed and its segment becomes entirely free, the segment is released to the arena immediately, instead of at the next empty-segment trimming pass.
| threshold | the allocation size in bytes. The default is DEFAULT_IMMEDIATE_RELEASE_THRESHOLD. 0 disables the immediate release. |
|
inline |
Set the padding byte.
| paddingByte | The padding byte. |
Set whether or not we should be storing the exact user size in memory.
| b | the boolean choice |
|
inline |
Set the number of deallocations between empty-segment trimming passes.
Memory segments that become entirely free are kept for later allocations. After every interval deallocations, the segments that are entirely free are released to the arena. A smaller interval keeps the footprint smaller, but releases and obtains segments more often.
| interval | the number of deallocations between the passes. The default is DEFAULT_TRIM_EMPTY_SEGMENTS_INTERVAL. 1 (or 0) releases empty segments on every deallocation. |
Validate the internal memory structures.