CernVM-FS  2.12.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
lru::LruCache< Key, Value >::MemoryAllocator< M > Class Template Reference
Inheritance diagram for lru::LruCache< Key, Value >::MemoryAllocator< M >:
Collaboration diagram for lru::LruCache< Key, Value >::MemoryAllocator< M >:

Public Member Functions

 MemoryAllocator (const unsigned int num_slots)
 
virtual ~MemoryAllocator ()
 
bool IsFull () const
 
T * Construct (const T object)
 
void Destruct (T *object)
 
T * Allocate ()
 
void Deallocate (T *slot)
 
uint64_t bytes_allocated ()
 

Static Public Member Functions

static double GetEntrySize ()
 

Private Member Functions

bool GetBit (const unsigned position)
 
void SetBit (const unsigned position)
 
void UnsetBit (const unsigned position)
 
- Private Member Functions inherited from SingleCopy
 SingleCopy ()
 

Private Attributes

unsigned int num_slots_
 
unsigned int num_free_slots_
 
unsigned int next_free_slot_
 
uint64_t bytes_allocated_
 
uint64_t * bitmap_
 
unsigned bits_per_block_
 
T * memory_
 

Detailed Description

template<class Key, class Value>
template<class M>
class lru::LruCache< Key, Value >::MemoryAllocator< M >

A special purpose memory allocator for the cache entries. It allocates enough memory for the maximal number of cache entries at startup, and assigns new ListEntryContent objects to a free spot in this memory pool (by overriding the 'new' and 'delete' operators of ListEntryContent).

Parameters
Tthe type of object to be allocated by this MemoryAllocator

Definition at line 112 of file lru.h.

Constructor & Destructor Documentation

template<class Key, class Value>
template<class M>
lru::LruCache< Key, Value >::MemoryAllocator< M >::MemoryAllocator ( const unsigned int  num_slots)
inlineexplicit

Creates a MemoryAllocator to handle a memory pool for objects of type T

Parameters
num_slotsthe number of slots to be allocated for the given datatype T

Definition at line 143 of file lru.h.

template<class Key, class Value>
template<class M>
virtual lru::LruCache< Key, Value >::MemoryAllocator< M >::~MemoryAllocator ( )
inlinevirtual

The memory allocator also frees all allocated data

Definition at line 174 of file lru.h.

Member Function Documentation

template<class Key, class Value>
template<class M>
T* lru::LruCache< Key, Value >::MemoryAllocator< M >::Allocate ( )
inline

Allocate a slot and returns a pointer to the memory.

Returns
a pointer to a chunk of the memory pool

Definition at line 202 of file lru.h.

Referenced by lru::LruCache< Key, Value >::MemoryAllocator< ConcreteListEntryContent >::Construct().

Here is the caller graph for this function:

template<class Key, class Value>
template<class M>
uint64_t lru::LruCache< Key, Value >::MemoryAllocator< M >::bytes_allocated ( )
inline

Definition at line 245 of file lru.h.

Referenced by lru::LruCache< shash::Any, MemoryBuffer >::Drop(), and lru::LruCache< shash::Any, MemoryBuffer >::LruCache().

Here is the caller graph for this function:

template<class Key, class Value>
template<class M>
T* lru::LruCache< Key, Value >::MemoryAllocator< M >::Construct ( const T  object)
inline

Definition at line 185 of file lru.h.

Referenced by lru::LruCache< Key, Value >::ListEntryHead< fuse_ino_t >::PushBack().

Here is the caller graph for this function:

template<class Key, class Value>
template<class M>
void lru::LruCache< Key, Value >::MemoryAllocator< M >::Deallocate ( T *  slot)
inline

Free a given slot in the memory pool

Parameters
slota pointer to the slot be freed

Definition at line 229 of file lru.h.

Referenced by lru::LruCache< Key, Value >::MemoryAllocator< ConcreteListEntryContent >::Destruct().

Here is the caller graph for this function:

template<class Key, class Value>
template<class M>
void lru::LruCache< Key, Value >::MemoryAllocator< M >::Destruct ( T *  object)
inline
template<class Key, class Value>
template<class M>
bool lru::LruCache< Key, Value >::MemoryAllocator< M >::GetBit ( const unsigned  position)
inlineprivate

Check a bit in the internal allocation bitmap.

Parameters
positionthe position to check
Returns
true if bit is set, otherwise false

Definition at line 253 of file lru.h.

Referenced by lru::LruCache< Key, Value >::MemoryAllocator< ConcreteListEntryContent >::Allocate(), and lru::LruCache< Key, Value >::MemoryAllocator< ConcreteListEntryContent >::Deallocate().

Here is the caller graph for this function:

template<class Key, class Value>
template<class M>
static double lru::LruCache< Key, Value >::MemoryAllocator< M >::GetEntrySize ( )
inlinestatic

Number of bytes for a single entry

Definition at line 167 of file lru.h.

template<class Key, class Value>
template<class M>
bool lru::LruCache< Key, Value >::MemoryAllocator< M >::IsFull ( ) const
inline

Check if the memory pool is full.

Returns
true if all slots are occupied, otherwise false

Definition at line 183 of file lru.h.

Referenced by lru::LruCache< Key, Value >::MemoryAllocator< ConcreteListEntryContent >::Allocate().

Here is the caller graph for this function:

template<class Key, class Value>
template<class M>
void lru::LruCache< Key, Value >::MemoryAllocator< M >::SetBit ( const unsigned  position)
inlineprivate

set a bit in the internal allocation bitmap

Parameters
positionthe number of the bit to be set

Definition at line 263 of file lru.h.

Referenced by lru::LruCache< Key, Value >::MemoryAllocator< ConcreteListEntryContent >::Allocate().

Here is the caller graph for this function:

template<class Key, class Value>
template<class M>
void lru::LruCache< Key, Value >::MemoryAllocator< M >::UnsetBit ( const unsigned  position)
inlineprivate

Clear a bit in the internal allocation bitmap

Parameters
positionthe number of the bit to be cleared

Definition at line 273 of file lru.h.

Referenced by lru::LruCache< Key, Value >::MemoryAllocator< ConcreteListEntryContent >::Deallocate().

Here is the caller graph for this function:

Member Data Documentation

template<class Key, class Value>
template<class M>
uint64_t lru::LruCache< Key, Value >::MemoryAllocator< M >::bytes_allocated_
private
template<class Key, class Value>
template<class M>
unsigned int lru::LruCache< Key, Value >::MemoryAllocator< M >::next_free_slot_
private

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