#include <pool_allocator.h>
Public Member Functions | |
DISPENSO_DLL_ACCESS | PoolAllocatorT (size_t chunkSize, size_t allocSize, std::function< void *(size_t)> allocFunc, std::function< void(void *)> deallocFunc) |
DISPENSO_DLL_ACCESS char * | alloc () |
DISPENSO_DLL_ACCESS void | dealloc (char *ptr) |
DISPENSO_DLL_ACCESS void | clear () |
size_t | totalChunkCapacity () const |
DISPENSO_DLL_ACCESS | ~PoolAllocatorT () |
A pool allocator to help reduce calls to the underlying allocation and deallocation functions.
Definition at line 29 of file pool_allocator.h.
dispenso::PoolAllocatorT< kThreadSafe >::PoolAllocatorT | ( | size_t | chunkSize, |
size_t | allocSize, | ||
std::function< void *(size_t)> | allocFunc, | ||
std::function< void(void *)> | deallocFunc | ||
) |
Construct a PoolAllocator.
chunkSize | The chunk size for each pool allocation |
allocSize | The size of underlying slabs to be chunked |
allocFunc | The underlying allocation function for allocating slabs |
deallocFunc | The underlying deallocation function. Currently only called on destruction. |
Definition at line 13 of file pool_allocator.cpp.
dispenso::PoolAllocatorT< kThreadSafe >::~PoolAllocatorT | ( | ) |
Destruct a PoolAllocator
Definition at line 104 of file pool_allocator.cpp.
char * dispenso::PoolAllocatorT< kThreadSafe >::alloc | ( | ) |
Allocate a chunk from a slab
Definition at line 28 of file pool_allocator.cpp.
void dispenso::PoolAllocatorT< kThreadSafe >::clear | ( | ) |
Effectively dealloc all previously allocated chunks. Useful for arenas. This function is not thread safe, and no previously allocated chunks may be dealloc'd after clear.
Definition at line 92 of file pool_allocator.cpp.
void dispenso::PoolAllocatorT< kThreadSafe >::dealloc | ( | char * | ptr | ) |
Deallocate a previously allocated chunk
ptr | The chunk to return to the available pool |
Definition at line 68 of file pool_allocator.cpp.
|
inline |
Get the total capicity allocated in chunks (how many alloc() could be called without triggering allocFunc() if all chunks were available)
Definition at line 70 of file pool_allocator.h.