#include <Pool.h>

Inheritance diagram for MemAllocator:
Collaboration diagram for MemAllocator:

Public Member Functions

 MemAllocator (char const *aLabel)
virtual ~MemAllocator ()
virtual int getStats (MemPoolStats *stats, int accumulate=0)=0
virtual MemPoolMeter const & getMeter () const =0
virtual void * alloc ()=0
virtual void freeOne (void *)=0
virtual char const * objectType () const
virtual size_t objectSize () const =0
virtual int getInUseCount ()=0
void zeroBlocks (bool doIt)
int inUseCount ()
virtual void setChunkSize (size_t)

Static Public Member Functions

static size_t RoundedSize (size_t minSize)

Protected Attributes

bool doZero

Private Attributes

const char * label

Detailed Description

a pool is a [growing] space for objects of the same size

Definition at line 178 of file Pool.h.

Constructor & Destructor Documentation

◆ MemAllocator()

MemAllocator::MemAllocator ( char const *  aLabel)

Definition at line 289 of file Pool.cc.

◆ ~MemAllocator()

virtual MemAllocator::~MemAllocator ( )

Definition at line 182 of file Pool.h.

References Ping::stats.

Member Function Documentation

◆ alloc()

◆ freeOne()

◆ getInUseCount()

virtual int MemAllocator::getInUseCount ( )
pure virtual

◆ getMeter()

virtual MemPoolMeter const& MemAllocator::getMeter ( ) const
pure virtual

◆ getStats()

virtual int MemAllocator::getStats ( MemPoolStats stats,
int  accumulate = 0 
pure virtual
statsObject to be filled with statistical data about pool.
Return values
Numberof objects in use, ie. allocated.

Implemented in MemPoolMalloc, and MemPoolChunked.

Referenced by Mem::AllocatorProxy::getStats(), memPoolGetGlobalStats(), and Mem::Report().

◆ inUseCount()

int MemAllocator::inUseCount ( )

Definition at line 113 of file Pool.cc.

Referenced by Mem::AllocatorProxy::inUseCount(), memInUse(), and memStringCount().

◆ objectSize()

virtual size_t MemAllocator::objectSize ( ) const
pure virtual

Implemented in MemImplementingAllocator.

Referenced by cbdataDump().

◆ objectType()

char const * MemAllocator::objectType ( ) const

Definition at line 107 of file Pool.cc.

Referenced by cbdataDump(), MemPoolChunked::getStats(), and MemPoolMalloc::getStats().

◆ RoundedSize()

size_t MemAllocator::RoundedSize ( size_t  minSize)
minSizeMinimum size needed to be allocated.
Return values
nSmallest size divisible by sizeof(void*)

Definition at line 293 of file Pool.cc.

Referenced by GetStrPool().

◆ setChunkSize()

virtual void MemAllocator::setChunkSize ( size_t  )

Allows you tune chunk size of pooling. Objects are allocated in chunks instead of individually. This conserves memory, reduces fragmentation. Because of that memory can be freed also only in chunks. Therefore there is tradeoff between memory conservation due to chunking and free memory fragmentation.

As a general guideline, increase chunk size only for pools that keep very many items for relatively long time.

Reimplemented in MemPoolChunked.

Definition at line 218 of file Pool.h.

Referenced by createRemovalPolicy_lru(), and Mem::Init().

◆ zeroBlocks()

void MemAllocator::zeroBlocks ( bool  doIt)

Member Data Documentation

◆ doZero

bool MemAllocator::doZero

Whether to zero memory on initial allocation and on return to the pool.

We do this on some pools because many object constructors are/were incomplete and we are afraid some code may use the object after free. These probems are becoming less common, so when possible set this to false.

Definition at line 233 of file Pool.h.

Referenced by MemPoolMalloc::allocate(), MemPoolMalloc::deallocate(), MemChunk::MemChunk(), and MemPoolChunked::push().

◆ label

const char* MemAllocator::label

Definition at line 236 of file Pool.h.

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






Web Site Translations