|
CookMem 1.4.0
A C++ memory context / allocator
|
#include <pool.h>
Public Types | |
| typedef std::size_t | size_type |
| typedef std::ptrdiff_t | difference_type |
| typedef T | value_type |
| typedef T * | pointer |
| typedef const T * | const_pointer |
A memory allocator.
Note that this class only provides the algorithm necessary to deal with small memory chunks. The actual ability to get memory segment (such as mmap memory pages) is deferred to memory arena.
pointer difference type
|
inline |
Constructor
| arena | Memory arena used to allocate memory segments. |
| logger | Logging facility used to log memory allocation and deallocation. |
| paddingSize | The number of bytes to pad after each allocation to detect out of bound access. 0 disables the padding check. |
Destructor.
It releases all the memory segments used.
Allocate memory from the memory pool.
| userSize | 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.
| userSize | 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 | ignored. |
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 maximum memory footprint.
|
inline |
Get the padding byte.
|
inline |
Get the number of padding bytes checked after each allocation.
|
inline |
Get the number of deallocations between empty-segment trimming passes.
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. |
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.
Print the memory segments and chunks of the pool to stdout. This is for debugging.
|
inline |
This function reallocate a memory.
| ptr | the current memory pointer. |
| newUserSize | the new size |
Release all the memory segments held by this MemPool.
|
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. This is similar to the mmap threshold of dlmalloc.
| 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.
It can only be changed if the current padding is false.
| 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 that all memory structures are correct.