dispenso
A library for task parallelism
 
Loading...
Searching...
No Matches
dispenso::PoolAllocatorT< kThreadSafe > Class Template Reference

#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 charalloc ()
 
DISPENSO_DLL_ACCESS void dealloc (char *ptr)
 
DISPENSO_DLL_ACCESS void clear ()
 
size_t totalChunkCapacity () const
 
DISPENSO_DLL_ACCESS ~PoolAllocatorT ()
 

Detailed Description

template<bool kThreadSafe>
class dispenso::PoolAllocatorT< kThreadSafe >

A pool allocator to help reduce calls to the underlying allocation and deallocation functions.

Definition at line 29 of file pool_allocator.h.

Constructor & Destructor Documentation

◆ PoolAllocatorT()

template<bool kThreadSafe>
dispenso::PoolAllocatorT< kThreadSafe >::PoolAllocatorT ( size_t  chunkSize,
size_t  allocSize,
std::function< void *(size_t)>  allocFunc,
std::function< void(void *)>  deallocFunc 
)

Construct a PoolAllocator.

Parameters
chunkSizeThe chunk size for each pool allocation
allocSizeThe size of underlying slabs to be chunked
allocFuncThe underlying allocation function for allocating slabs
deallocFuncThe underlying deallocation function. Currently only called on destruction.

Definition at line 13 of file pool_allocator.cpp.

◆ ~PoolAllocatorT()

template<bool kThreadSafe>
dispenso::PoolAllocatorT< kThreadSafe >::~PoolAllocatorT ( )

Destruct a PoolAllocator

Definition at line 104 of file pool_allocator.cpp.

Member Function Documentation

◆ alloc()

template<bool kThreadSafe>
char * dispenso::PoolAllocatorT< kThreadSafe >::alloc ( )

Allocate a chunk from a slab

Returns
The pointer to a buffer of chunkSize bytes

Definition at line 28 of file pool_allocator.cpp.

◆ clear()

template<bool kThreadSafe>
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.

◆ dealloc()

template<bool kThreadSafe>
void dispenso::PoolAllocatorT< kThreadSafe >::dealloc ( char ptr)

Deallocate a previously allocated chunk

Parameters
ptrThe chunk to return to the available pool

Definition at line 68 of file pool_allocator.cpp.

◆ totalChunkCapacity()

template<bool kThreadSafe>
size_t dispenso::PoolAllocatorT< kThreadSafe >::totalChunkCapacity ( ) const
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.


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