#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 288 of file Pool.cc.

◆ ~MemAllocator()

virtual MemAllocator::~MemAllocator ( )

Definition at line 182 of file Pool.h.

Member Function Documentation

◆ alloc()

◆ freeOne()

virtual void MemAllocator::freeOne ( void *  )
pure virtual

◆ getInUseCount()

virtual int MemAllocator::getInUseCount ( )
pure virtual

◆ getMeter()

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

Implemented in MemImplementingAllocator.

Referenced by cbdataDump(), and Mem::Report().

◆ 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 MemPoolChunked, and MemPoolMalloc.

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

◆ inUseCount()

int MemAllocator::inUseCount ( )

Definition at line 112 of file Pool.cc.

References getInUseCount().

Referenced by 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 106 of file Pool.cc.

References label.

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 292 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)

Definition at line 205 of file Pool.h.

References doZero.

Referenced by Mem::AllocatorProxy::getAllocator(), GetStrPool(), and memDataInit().

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 MemChunk::MemChunk(), MemPoolMalloc::allocate(), MemPoolMalloc::deallocate(), MemPoolChunked::push(), and zeroBlocks().

◆ label

const char* MemAllocator::label

Definition at line 236 of file Pool.h.

Referenced by objectType().

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






Web Site Translations