#include <Allocator.h>


Public Member Functions | |
Allocator (const char *const aLabel, const size_t sz) | |
virtual size_t | getStats (PoolStats &)=0 |
void * | alloc () |
provide (and reserve) memory suitable for storing one object More... | |
void | freeOne (void *obj) |
return memory reserved by alloc() More... | |
int | getInUseCount () const |
the difference between the number of alloc() and freeOne() calls More... | |
void | zeroBlocks (const bool doIt) |
virtual void | setChunkSize (size_t) |
XXX: Misplaced – not all allocators have a notion of a "chunk". See MemPoolChunked. More... | |
virtual bool | idleTrigger (int shift) const =0 |
virtual void | clean (time_t maxage)=0 |
void | flushCounters () |
Static Public Member Functions | |
static size_t | RoundedSize (const size_t minSize) |
Public Attributes | |
size_t | countAlloc = 0 |
the number of calls to Mem::Allocator::alloc() since last flush More... | |
size_t | countSavedAllocs = 0 |
the number of malloc()/calloc() calls avoided since last flush More... | |
size_t | countFreeOne = 0 |
the number of calls to Mem::Allocator::freeOne() since last flush More... | |
const char *const | label |
brief description of objects returned by alloc() More... | |
const size_t | objectSize |
the size (in bytes) of objects managed by this allocator More... | |
PoolMeter | meter |
statistics tracked for this allocator More... | |
Static Public Attributes | |
static const size_t | FlushLimit = 1000 |
Flush counters to 'meter' after flush limit allocations. More... | |
Protected Member Functions | |
virtual void * | allocate ()=0 |
*alloc() More... | |
virtual void | deallocate (void *)=0 |
freeOne(void *) More... | |
Protected Attributes | |
bool | doZero = true |
Detailed Description
An interface for memory allocators that deal with fixed-size objects. Allocators may optimize repeated de/allocations using memory pools.
Definition at line 21 of file Allocator.h.
Constructor & Destructor Documentation
◆ Allocator()
|
inline |
Definition at line 27 of file Allocator.h.
Member Function Documentation
◆ alloc()
|
inline |
Definition at line 40 of file Allocator.h.
References allocate(), countAlloc, flushCounters(), and FlushLimit.
Referenced by Mem::AllocatorProxy::alloc(), authenticateDigestNonceNew(), cbdataInternalAlloc(), memAllocate(), squidaio_close(), squidaio_init(), squidaio_open(), squidaio_read(), squidaio_stat(), squidaio_unlink(), and squidaio_write().
◆ allocate()
|
protectedpure virtual |
◆ clean()
|
pure virtual |
Implemented in MemPoolChunked, and MemPoolMalloc.
◆ deallocate()
|
protectedpure virtual |
◆ flushCounters()
|
inline |
Flush temporary counter values into the statistics held in 'meter'.
Definition at line 70 of file Allocator.h.
References countAlloc, countFreeOne, countSavedAllocs, Mem::PoolMeter::gb_allocated, Mem::PoolMeter::gb_freed, Mem::PoolMeter::gb_saved, meter, objectSize, and Mem::PoolMeter::mgb_t::update().
Referenced by MemPoolChunked::~MemPoolChunked(), alloc(), and MemPoolChunked::clean().
◆ freeOne()
|
inline |
Definition at line 47 of file Allocator.h.
References assert, countFreeOne, deallocate(), objectSize, and VALGRIND_CHECK_MEM_IS_ADDRESSABLE.
Referenced by cbdata::~cbdata(), authenticateDigestNonceDelete(), memFree(), and squidaio_cleanup_request().
◆ getInUseCount()
|
inline |
Definition at line 55 of file Allocator.h.
References Mem::Meter::currentLevel(), Mem::PoolMeter::inuse, and meter.
Referenced by MemPoolChunked::~MemPoolChunked(), MemPoolMalloc::~MemPoolMalloc(), MemPoolChunked::getStats(), MemPoolMalloc::getStats(), StoreEntry::inUseCount(), memInUse(), and memStringCount().
◆ getStats()
fill the given object with statistical data about pool
- Returns
- Number of objects in use, ie. allocated.
Implemented in MemPoolChunked, and MemPoolMalloc.
◆ idleTrigger()
|
pure virtual |
Implemented in MemPoolChunked, and MemPoolMalloc.
◆ RoundedSize()
- Parameters
-
minSize Minimum size needed to be allocated.
- Return values
-
n Smallest size divisible by sizeof(void*)
Definition at line 89 of file Allocator.h.
Referenced by GetStrPool().
◆ setChunkSize()
|
inlinevirtual |
Reimplemented in MemPoolChunked.
Definition at line 61 of file Allocator.h.
Referenced by Mem::Init().
◆ zeroBlocks()
|
inline |
- See also
- doZero
Definition at line 58 of file Allocator.h.
References doZero.
Referenced by Mem::AllocatorProxy::getAllocator(), GetStrPool(), and memDataInit().
Member Data Documentation
◆ countAlloc
size_t Mem::Allocator::countAlloc = 0 |
Definition at line 94 of file Allocator.h.
Referenced by alloc(), and flushCounters().
◆ countFreeOne
size_t Mem::Allocator::countFreeOne = 0 |
Definition at line 100 of file Allocator.h.
Referenced by flushCounters(), and freeOne().
◆ countSavedAllocs
size_t Mem::Allocator::countSavedAllocs = 0 |
Definition at line 97 of file Allocator.h.
Referenced by MemPoolMalloc::allocate(), flushCounters(), and MemPoolChunked::get().
◆ doZero
|
protected |
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. When possible, set this to false to avoid zeroing overheads.
Definition at line 126 of file Allocator.h.
Referenced by MemChunk::MemChunk(), MemPoolMalloc::allocate(), MemPoolMalloc::deallocate(), MemPoolChunked::push(), and zeroBlocks().
◆ FlushLimit
|
static |
Definition at line 25 of file Allocator.h.
Referenced by alloc().
◆ label
const char* const Mem::Allocator::label |
Definition at line 105 of file Allocator.h.
Referenced by MemPoolChunked::getStats(), and MemPoolMalloc::getStats().
◆ meter
PoolMeter Mem::Allocator::meter |
Definition at line 111 of file Allocator.h.
Referenced by MemChunk::MemChunk(), MemChunk::~MemChunk(), MemPoolChunked::allocate(), MemPoolMalloc::allocate(), MemPoolMalloc::clean(), MemPoolChunked::deallocate(), MemPoolMalloc::deallocate(), flushCounters(), getInUseCount(), MemPoolChunked::getStats(), MemPoolMalloc::getStats(), MemPoolChunked::idleTrigger(), and Mem::Report().
◆ objectSize
const size_t Mem::Allocator::objectSize |
Definition at line 108 of file Allocator.h.
Referenced by MemChunk::MemChunk(), MemPoolMalloc::allocate(), MemPoolMalloc::deallocate(), flushCounters(), freeOne(), MemPoolChunked::get(), MemPoolChunked::getStats(), MemPoolMalloc::getStats(), MemPoolChunked::push(), and MemPoolChunked::setChunkSize().
The documentation for this class was generated from the following file:
- src/mem/Allocator.h