pion-net  4.0.7
Classes | Public Member Functions | Protected Types | Protected Member Functions
pion::PionPoolAllocator Class Reference

#include <PionPoolAllocator.hpp>

List of all members.

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

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


Member Function Documentation

pion::PionPoolAllocator::BOOST_STATIC_ASSERT ( MaxSize >=  MinSize) [protected]

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

void pion::PionPoolAllocator::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 getPool(), pion::PionPoolAllocator::FixedSizeAlloc::m_free_ptr, pion::PionPoolAllocator::FixedSizeAlloc::m_mutex, and pion::PionPoolAllocator::FixedSizeAlloc::m_pool.

FixedSizeAlloc* pion::PionPoolAllocator::getPool ( const std::size_t  n) [inline, protected]

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 malloc(), and free().

void* pion::PionPoolAllocator::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 getPool(), pion::PionPoolAllocator::FixedSizeAlloc::m_free_ptr, pion::PionPoolAllocator::FixedSizeAlloc::m_mutex, and pion::PionPoolAllocator::FixedSizeAlloc::m_pool.

bool pion::PionPoolAllocator::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: