#include <Pool.h>

Inheritance diagram for MemImplementingAllocator:
Collaboration diagram for MemImplementingAllocator:

Public Member Functions

 MemImplementingAllocator (char const *aLabel, size_t aSize)
 
virtual ~MemImplementingAllocator ()
 
virtual MemPoolMeter const & getMeter () const
 
virtual MemPoolMetergetMeter ()
 
virtual void flushMetersFull ()
 
virtual void flushMeters ()
 
virtual void * alloc ()
 
virtual void freeOne (void *)
 
virtual bool idleTrigger (int shift) const =0
 
virtual void clean (time_t maxage)=0
 
virtual size_t objectSize () const
 
virtual int getInUseCount ()=0
 
virtual int getStats (MemPoolStats *stats, int accumulate=0)=0
 
virtual char const * objectType () const
 
void zeroBlocks (bool doIt)
 
int inUseCount ()
 
virtual void setChunkSize (size_t)
 

Static Public Member Functions

static size_t RoundedSize (size_t minSize)
 

Public Attributes

MemImplementingAllocatornext
 
size_t alloc_calls
 
size_t free_calls
 
size_t saved_calls
 
size_t obj_size
 

Protected Member Functions

virtual void * allocate ()=0
 
virtual void deallocate (void *, bool aggressive)=0
 

Protected Attributes

MemPoolMeter meter
 
int memPID
 
bool doZero
 

Detailed Description

Definition at line 240 of file Pool.h.

Constructor & Destructor Documentation

MemImplementingAllocator::MemImplementingAllocator ( char const *  aLabel,
size_t  aSize 
)

Definition at line 306 of file Pool.cc.

References assert, MemPools::GetInstance(), memPID, next, NULL, Pool_id_counter, and MemPools::pools.

MemImplementingAllocator::~MemImplementingAllocator ( )
virtual

Definition at line 327 of file Pool.cc.

References assert, MemPools::GetInstance(), next, NULL, MemPools::poolCount, and MemPools::pools.

Member Function Documentation

void * MemImplementingAllocator::alloc ( )
virtual

Allocate one element from the pool

Implements MemAllocator.

Definition at line 197 of file Pool.cc.

References alloc_calls, allocate(), FLUSH_LIMIT, and flushMeters().

virtual void* MemImplementingAllocator::allocate ( )
protectedpure virtual

Implemented in MemPoolMalloc, and MemPoolChunked.

Referenced by alloc().

virtual void MemImplementingAllocator::clean ( time_t  maxage)
pure virtual

Implemented in MemPoolMalloc, and MemPoolChunked.

Referenced by MemPools::clean().

virtual void MemImplementingAllocator::deallocate ( void *  ,
bool  aggressive 
)
protectedpure virtual

Implemented in MemPoolMalloc, and MemPoolChunked.

Referenced by freeOne().

void MemImplementingAllocator::flushMeters ( )
virtual
void MemImplementingAllocator::flushMetersFull ( )
virtual
void MemImplementingAllocator::freeOne ( void *  obj)
virtual

Free a element allocated by MemImplementingAllocator::alloc()

Implements MemAllocator.

Definition at line 206 of file Pool.cc.

References assert, deallocate(), free_calls, MemPools::GetInstance(), NULL, obj_size, and VALGRIND_CHECK_MEM_IS_ADDRESSABLE.

virtual int MemImplementingAllocator::getInUseCount ( )
pure virtual

Implements MemAllocator.

Implemented in MemPoolMalloc, and MemPoolChunked.

MemPoolMeter const & MemImplementingAllocator::getMeter ( ) const
virtual

Implements MemAllocator.

Definition at line 349 of file Pool.cc.

References meter.

Referenced by flushMetersFull(), MemChunk::MemChunk(), and MemChunk::~MemChunk().

MemPoolMeter & MemImplementingAllocator::getMeter ( )
virtual

Definition at line 355 of file Pool.cc.

References meter.

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

Implemented in MemPoolMalloc, and MemPoolChunked.

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

virtual bool MemImplementingAllocator::idleTrigger ( int  shift) const
pure virtual

Implemented in MemPoolChunked, and MemPoolMalloc.

Referenced by MemPools::clean().

int MemAllocator::inUseCount ( )
inherited

Definition at line 113 of file Pool.cc.

References MemAllocator::getInUseCount().

Referenced by memInUse(), and memStringCount().

size_t MemImplementingAllocator::objectSize ( ) const
virtual

Implements MemAllocator.

Definition at line 361 of file Pool.cc.

References obj_size.

char const * MemAllocator::objectType ( ) const
virtualinherited

Definition at line 107 of file Pool.cc.

References MemAllocator::label.

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

size_t MemAllocator::RoundedSize ( size_t  minSize)
staticinherited
Parameters
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().

virtual void MemAllocator::setChunkSize ( size_t  )
inlinevirtualinherited

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.

Note
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().

void MemAllocator::zeroBlocks ( bool  doIt)
inlineinherited

Definition at line 205 of file Pool.h.

References MemAllocator::doZero.

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

Member Data Documentation

size_t MemImplementingAllocator::alloc_calls

Definition at line 272 of file Pool.h.

Referenced by alloc(), and flushMeters().

bool MemAllocator::doZero
protectedinherited

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(), MemPoolChunked::push(), and MemAllocator::zeroBlocks().

size_t MemImplementingAllocator::free_calls

Definition at line 273 of file Pool.h.

Referenced by flushMeters(), and freeOne().

int MemImplementingAllocator::memPID
protected

Definition at line 268 of file Pool.h.

Referenced by MemImplementingAllocator().

MemImplementingAllocator* MemImplementingAllocator::next

Definition at line 270 of file Pool.h.

Referenced by MemImplementingAllocator(), memPoolIterateNext(), and ~MemImplementingAllocator().

size_t MemImplementingAllocator::saved_calls

Definition at line 274 of file Pool.h.

Referenced by MemPoolMalloc::allocate(), flushMeters(), and MemPoolChunked::get().


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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors