pion-net  4.0.9
Classes | Public Member Functions | Protected Types | Protected Member Functions | List of all members
pion::PionPoolAllocator< MinSize, MaxSize > Class Template Reference

#include <PionPoolAllocator.hpp>

Inherits noncopyable.

Classes

struct  FixedSizeAlloc
 

Public Member Functions

virtual ~PionPoolAllocator ()
 virtual destructor
 
 PionPoolAllocator (void)
 default constructor
 
void * malloc (std::size_t n)
 
void free (void *ptr, std::size_t n)
 
bool release_memory (size_t pad=10240000UL)
 

Protected Types

enum  { NumberOfAllocs = ((MaxSize-1) / MinSize) + 1 }
 constant representing the number of fixed-size pool allocators
 
typedef void * FreeListPtr
 

Protected Member Functions

 BOOST_STATIC_ASSERT (MaxSize >=MinSize)
 
 BOOST_STATIC_ASSERT (MaxSize%MinSize==0)
 
FixedSizeAllocgetPool (const std::size_t n)
 

Detailed Description

template<std::size_t MinSize = 16, std::size_t MaxSize = 256>
class pion::PionPoolAllocator< MinSize, MaxSize >

PionPoolAllocator: a thread-safe, small object allocator that sacrifices memory utilization for performance. It combines a collection of fixed-size pooled memory allocators with lock-free caches to achieve nearly wait-free, constant time performance when used for an extended period of time

Definition at line 52 of file PionPoolAllocator.hpp.

Member Function Documentation

template<std::size_t MinSize = 16, std::size_t MaxSize = 256>
pion::PionPoolAllocator< MinSize, MaxSize >::BOOST_STATIC_ASSERT ( MaxSize >=  MinSize)
protected

ensure that: a) MaxSize >= MinSize b) MaxSize is a multiple of MinSize c) MinSize >= sizeof(FreeNodePtr) [usually 16]

template<std::size_t MinSize = 16, std::size_t MaxSize = 256>
void pion::PionPoolAllocator< MinSize, MaxSize >::free ( void *  ptr,
std::size_t  n 
)
inline

deallocates a block of memory

Parameters
ptrraw pointer to the block of memory
nrequested size of the memory block, in bytes (actual size may be larger)

Definition at line 106 of file PionPoolAllocator.hpp.

References pion::PionPoolAllocator< MinSize, MaxSize >::getPool(), pion::PionPoolAllocator< MinSize, MaxSize >::FixedSizeAlloc::m_free_ptr, pion::PionPoolAllocator< MinSize, MaxSize >::FixedSizeAlloc::m_mutex, and pion::PionPoolAllocator< MinSize, MaxSize >::FixedSizeAlloc::m_pool.

template<std::size_t MinSize = 16, std::size_t MaxSize = 256>
FixedSizeAlloc* pion::PionPoolAllocator< MinSize, MaxSize >::getPool ( const std::size_t  n)
inlineprotected

gets an appropriate fixed-size pool allocator

Parameters
nthe number of bytes to be (de)allocated
Returns
FixedSizeAlloc* pointer to the appropriate fixed-size allocator

Definition at line 236 of file PionPoolAllocator.hpp.

Referenced by pion::PionPoolAllocator< MinSize, MaxSize >::free(), and pion::PionPoolAllocator< MinSize, MaxSize >::malloc().

template<std::size_t MinSize = 16, std::size_t MaxSize = 256>
void* pion::PionPoolAllocator< MinSize, MaxSize >::malloc ( std::size_t  n)
inline

allocates a block of memory

Parameters
nminimum size of the new memory block, in bytes
Returns
void * raw pointer to the new memory block

Definition at line 76 of file PionPoolAllocator.hpp.

References pion::PionPoolAllocator< MinSize, MaxSize >::getPool(), pion::PionPoolAllocator< MinSize, MaxSize >::FixedSizeAlloc::m_free_ptr, pion::PionPoolAllocator< MinSize, MaxSize >::FixedSizeAlloc::m_mutex, and pion::PionPoolAllocator< MinSize, MaxSize >::FixedSizeAlloc::m_pool.

template<std::size_t MinSize = 16, std::size_t MaxSize = 256>
bool pion::PionPoolAllocator< MinSize, MaxSize >::release_memory ( size_t  pad = 10240000UL)
inline

releases every memory block that does not have any allocated chunks

Parameters
padpadding bytes passed to malloc_trim(), if it's supported (default=10MB)
Returns
bool true if at least one block of memory was released

Definition at line 141 of file PionPoolAllocator.hpp.


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