ATLAS Offline Software
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Types | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
DataPool< VALUE, clear > Class Template Reference

a typed memory pool that saves time spent allocation small object. This is typically used by container such as DataVector and DataList More...

#include <DataPool.h>

Collaboration diagram for DataPool< VALUE, clear >:

Classes

class  const_iterator
 
class  iterator
 

Public Types

typedef handle_t::pointer pointer
 
typedef size_t size_type
 

Public Member Functions

 DataPool (size_type n=0)
 Constructors: More...
 
 DataPool (const EventContext &ctx, size_type n=0)
 
 DataPool (SG::Arena *arena, size_type n=0)
 
void reset ()
 release all elements in the pool. More...
 
void erase ()
 free all memory in the pool. More...
 
void reserve (unsigned int size)
 Set the desired capacity. More...
 
void prepareToAdd (unsigned int size)
 Prepare to add cached elements. More...
 
unsigned int capacity ()
 return capacity of pool OK More...
 
unsigned int allocated ()
 return size already allocated OK More...
 
iterator begin ()
 begin iterators over pool More...
 
const_iterator begin () const
 
iterator end ()
 the end() method will allow looping over only valid elements and not over ALL elements of the pool More...
 
const_iterator end () const
 
pointer nextElementPtr ()
 obtain the next available element in pool by pointer pool is resized if its limit has been reached One must be sure to completely reset each object since it has values set in the previous event. More...
 

Static Public Member Functions

static const std::string & typeName ()
 typename of pool More...
 

Private Types

typedef SG::ArenaPoolAllocator alloc_t
 
typedef SG::ArenaCachingHandle< VALUE, alloc_thandle_t
 

Static Private Member Functions

static alloc_t::Params initParams ()
 
static void callClear (SG::ArenaAllocatorBase::pointer p)
 

Private Attributes

handle_t m_handle
 

Static Private Attributes

static const alloc_t::Params s_params
 
static constexpr size_t s_minRefCount = 1024
 minimum number of elements in pool More...
 

Detailed Description

template<typename VALUE, DataPoolClearFuncPtr_t< VALUE > clear = nullptr>
class DataPool< VALUE, clear >

a typed memory pool that saves time spent allocation small object. This is typically used by container such as DataVector and DataList

A DataPool instance, acts as handle to the pool for the declared type. In the typical DataVector usage each store has a collection of pools distinguished by type. So for the same active store the same pool is used.

Declaring DataPool instances as static will cause thread-safety problems, and thus should no longer be done.

Also be aware that a creating a DataPool object acquires a lock on the underlying thread-specific allocator. If you're just using one at a time, there shouldn't be a problem. There is a potential for deadlock if you have a block of code that creates two DataPool objects, and another code block that creates DataPool objects for the same types but in the opposite order.

You can optionally provide (as a template argument) a function to be called on an object when it is returned to the pool. This can be used to reset the state, release memory, etc. This must be a static function, not a lambda, and since it's used as a template argument, it should not be in an anonymous namespace (should have public linkage). Also be aware that clear argument will have an effect only for the first DataPool object to be created for a given VALUE.

Author
Srini Rajagopalan, scott snyder

Definition at line 46 of file DataPool.h.

Member Typedef Documentation

◆ alloc_t

template<typename VALUE , DataPoolClearFuncPtr_t< VALUE > clear = nullptr>
typedef SG::ArenaPoolAllocator DataPool< VALUE, clear >::alloc_t
private

Definition at line 49 of file DataPool.h.

◆ handle_t

template<typename VALUE , DataPoolClearFuncPtr_t< VALUE > clear = nullptr>
typedef SG::ArenaCachingHandle<VALUE, alloc_t> DataPool< VALUE, clear >::handle_t
private

Definition at line 50 of file DataPool.h.

◆ pointer

template<typename VALUE , DataPoolClearFuncPtr_t< VALUE > clear = nullptr>
typedef handle_t::pointer DataPool< VALUE, clear >::pointer

Definition at line 53 of file DataPool.h.

◆ size_type

template<typename VALUE , DataPoolClearFuncPtr_t< VALUE > clear = nullptr>
typedef size_t DataPool< VALUE, clear >::size_type

Definition at line 54 of file DataPool.h.

Constructor & Destructor Documentation

◆ DataPool() [1/3]

template<typename VALUE , DataPoolClearFuncPtr_t< VALUE > clear = nullptr>
DataPool< VALUE, clear >::DataPool ( size_type  n = 0)

Constructors:

◆ DataPool() [2/3]

template<typename VALUE , DataPoolClearFuncPtr_t< VALUE > clear = nullptr>
DataPool< VALUE, clear >::DataPool ( const EventContext &  ctx,
size_type  n = 0 
)

◆ DataPool() [3/3]

template<typename VALUE , DataPoolClearFuncPtr_t< VALUE > clear = nullptr>
DataPool< VALUE, clear >::DataPool ( SG::Arena arena,
size_type  n = 0 
)

Member Function Documentation

◆ allocated()

template<typename VALUE , DataPoolClearFuncPtr_t< VALUE > clear = nullptr>
unsigned int DataPool< VALUE, clear >::allocated ( )

return size already allocated OK

◆ begin() [1/2]

template<typename VALUE , DataPoolClearFuncPtr_t< VALUE > clear = nullptr>
iterator DataPool< VALUE, clear >::begin ( )

begin iterators over pool

◆ begin() [2/2]

template<typename VALUE , DataPoolClearFuncPtr_t< VALUE > clear = nullptr>
const_iterator DataPool< VALUE, clear >::begin ( ) const

◆ callClear()

template<typename VALUE , DataPoolClearFuncPtr_t< VALUE > clear = nullptr>
static void DataPool< VALUE, clear >::callClear ( SG::ArenaAllocatorBase::pointer  p)
staticprivate

◆ capacity()

template<typename VALUE , DataPoolClearFuncPtr_t< VALUE > clear = nullptr>
unsigned int DataPool< VALUE, clear >::capacity ( )

return capacity of pool OK

◆ end() [1/2]

template<typename VALUE , DataPoolClearFuncPtr_t< VALUE > clear = nullptr>
iterator DataPool< VALUE, clear >::end ( )

the end() method will allow looping over only valid elements and not over ALL elements of the pool

◆ end() [2/2]

template<typename VALUE , DataPoolClearFuncPtr_t< VALUE > clear = nullptr>
const_iterator DataPool< VALUE, clear >::end ( ) const

◆ erase()

template<typename VALUE , DataPoolClearFuncPtr_t< VALUE > clear = nullptr>
void DataPool< VALUE, clear >::erase ( )

free all memory in the pool.

◆ initParams()

template<typename VALUE , DataPoolClearFuncPtr_t< VALUE > clear = nullptr>
static alloc_t::Params DataPool< VALUE, clear >::initParams ( )
staticprivate

◆ nextElementPtr()

template<typename VALUE , DataPoolClearFuncPtr_t< VALUE > clear = nullptr>
pointer DataPool< VALUE, clear >::nextElementPtr ( )

obtain the next available element in pool by pointer pool is resized if its limit has been reached One must be sure to completely reset each object since it has values set in the previous event.

◆ prepareToAdd()

template<typename VALUE , DataPoolClearFuncPtr_t< VALUE > clear = nullptr>
void DataPool< VALUE, clear >::prepareToAdd ( unsigned int  size)

Prepare to add cached elements.

Parameters
sizeAdditional elements to add

If (current capacity - allocated elements) is less than the requested elements additional space will be allocated by calling reserve (allocated + size). Otherwise nothing will be done

◆ reserve()

template<typename VALUE , DataPoolClearFuncPtr_t< VALUE > clear = nullptr>
void DataPool< VALUE, clear >::reserve ( unsigned int  size)

Set the desired capacity.

Parameters
sizeThe desired capacity

If size is greater than the total number of elements currently cached (allocated), then space for more will be allocated. This will be done in blocks. Therefore the allocator may allocate more elements than is requested.

If size is smaller than the total number of elements currently cached, as many blocks as possible will be released back to the system.

◆ reset()

template<typename VALUE , DataPoolClearFuncPtr_t< VALUE > clear = nullptr>
void DataPool< VALUE, clear >::reset ( )

release all elements in the pool.

◆ typeName()

template<typename VALUE , DataPoolClearFuncPtr_t< VALUE > clear = nullptr>
static const std::string& DataPool< VALUE, clear >::typeName ( )
static

typename of pool

Member Data Documentation

◆ m_handle

template<typename VALUE , DataPoolClearFuncPtr_t< VALUE > clear = nullptr>
handle_t DataPool< VALUE, clear >::m_handle
private

Definition at line 182 of file DataPool.h.

◆ s_minRefCount

template<typename VALUE , DataPoolClearFuncPtr_t< VALUE > clear = nullptr>
constexpr size_t DataPool< VALUE, clear >::s_minRefCount = 1024
staticconstexprprivate

minimum number of elements in pool

Definition at line 187 of file DataPool.h.

◆ s_params

template<typename VALUE , DataPoolClearFuncPtr_t< VALUE > clear = nullptr>
const alloc_t::Params DataPool< VALUE, clear >::s_params
staticprivate

Definition at line 184 of file DataPool.h.


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