lcls2
C++ API: public headers of xtcdata, psalg, psdaq and psana
Loading...
Searching...
No Matches
Pds::Eb::IndexPoolBase Class Reference

Fixed array of a power-of-2 number of equal-size objects, addressed by a key masked to the array size, with a per-slot allocated flag and allocation counters. More...

#include <IndexPool.hh>

Inherited by Pds::Eb::IndexPoolBaseW< std::mutex >.

Public Member Functions

 IndexPoolBase (size_t sizeofObject, unsigned numberofObjects)
 Allocate numberofObjects slots of sizeofObject bytes (16-byte aligned storage), all free.
 
 ~IndexPoolBase ()
 Does nothing; empty body.
 
bool isAllocated (unsigned key) const
 Return true if the slot for key (masked) is allocated.
 
void * allocate (unsigned key)
 Mark the slot for key (masked) allocated and return its address, or return nullptr if it is already allocated.
 
void free (unsigned key)
 Mark the slot for key (masked) free and count a free (also counted if the slot was not allocated).
 
void free (const void *buf)
 Free the slot that contains buf (found with index()).
 
const void * buffer () const
 Return the start of the object storage.
 
size_t size () const
 Return the storage size in bytes.
 
unsigned mask () const
 Return the key mask (number of objects minus 1).
 
char & operator[] (unsigned key)
 Return a reference to the first byte of the slot for key (masked); the allocated flag is not checked.
 
const char & operator[] (unsigned key) const
 Return a const reference to the first byte of the slot for key (masked); the allocated flag is not checked.
 
unsigned index (const void *buf) const
 Return the slot index of buf (its byte offset from the storage start divided by the object size).
 
size_t sizeofObject () const
 Return the object size in bytes.
 
size_t numberofObjects () const
 Return the number of slots (mask + 1).
 
const uint64_t & numberofAllocs () const
 Return a reference to the allocation counter.
 
const uint64_t & numberofFrees () const
 Return a reference to the free counter.
 
int64_t numberofAllocatedObjects () const
 Return the number of allocations minus the number of frees.
 
int64_t numberofFreeObjects () const
 Return numberofObjects() minus numberofAllocatedObjects().
 
void clear ()
 Mark all slots free and zero both counters.
 
void dump () const
 Print the storage size and address, the mask, the object size, the slot count and the counters to stdout.
 

Detailed Description

Fixed array of a power-of-2 number of equal-size objects, addressed by a key masked to the array size, with a per-slot allocated flag and allocation counters.

Not thread-safe; see IndexPoolBaseW.

Constructor & Destructor Documentation

◆ IndexPoolBase()

Pds::Eb::IndexPoolBase::IndexPoolBase ( size_t  sizeofObject,
unsigned  numberofObjects 
)
inline

Allocate numberofObjects slots of sizeofObject bytes (16-byte aligned storage), all free.

Throws a C string if numberofObjects is not a power of 2.

◆ ~IndexPoolBase()

Pds::Eb::IndexPoolBase::~IndexPoolBase ( )
inline

Does nothing; empty body.

Member Function Documentation

◆ allocate()

void * Pds::Eb::IndexPoolBase::allocate ( unsigned  key)
inline

Mark the slot for key (masked) allocated and return its address, or return nullptr if it is already allocated.

◆ buffer()

const void * Pds::Eb::IndexPoolBase::buffer ( ) const
inline

Return the start of the object storage.

◆ clear()

void Pds::Eb::IndexPoolBase::clear ( )

Mark all slots free and zero both counters.

◆ dump()

void Pds::Eb::IndexPoolBase::dump ( ) const

Print the storage size and address, the mask, the object size, the slot count and the counters to stdout.

◆ free() [1/2]

void Pds::Eb::IndexPoolBase::free ( const void *  buf)
inline

Free the slot that contains buf (found with index()).

◆ free() [2/2]

void Pds::Eb::IndexPoolBase::free ( unsigned  key)
inline

Mark the slot for key (masked) free and count a free (also counted if the slot was not allocated).

◆ index()

unsigned Pds::Eb::IndexPoolBase::index ( const void *  buf) const
inline

Return the slot index of buf (its byte offset from the storage start divided by the object size).

Note that the body's assert(key & ~_mask) fails for in-range keys when assertions are enabled.

◆ isAllocated()

bool Pds::Eb::IndexPoolBase::isAllocated ( unsigned  key) const
inline

Return true if the slot for key (masked) is allocated.

◆ mask()

unsigned Pds::Eb::IndexPoolBase::mask ( ) const
inline

Return the key mask (number of objects minus 1).

◆ numberofAllocatedObjects()

int64_t Pds::Eb::IndexPoolBase::numberofAllocatedObjects ( ) const
inline

Return the number of allocations minus the number of frees.

◆ numberofAllocs()

const uint64_t & Pds::Eb::IndexPoolBase::numberofAllocs ( ) const
inline

Return a reference to the allocation counter.

◆ numberofFreeObjects()

int64_t Pds::Eb::IndexPoolBase::numberofFreeObjects ( ) const
inline

◆ numberofFrees()

const uint64_t & Pds::Eb::IndexPoolBase::numberofFrees ( ) const
inline

Return a reference to the free counter.

◆ numberofObjects()

size_t Pds::Eb::IndexPoolBase::numberofObjects ( ) const
inline

Return the number of slots (mask + 1).

◆ operator[]() [1/2]

char & Pds::Eb::IndexPoolBase::operator[] ( unsigned  key)
inline

Return a reference to the first byte of the slot for key (masked); the allocated flag is not checked.

◆ operator[]() [2/2]

const char & Pds::Eb::IndexPoolBase::operator[] ( unsigned  key) const
inline

Return a const reference to the first byte of the slot for key (masked); the allocated flag is not checked.

◆ size()

size_t Pds::Eb::IndexPoolBase::size ( ) const
inline

Return the storage size in bytes.

◆ sizeofObject()

size_t Pds::Eb::IndexPoolBase::sizeofObject ( ) const
inline

Return the object size in bytes.


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