ATLAS Offline Software
|
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>
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_t > | handle_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... | |
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
.
Definition at line 46 of file DataPool.h.
|
private |
Definition at line 49 of file DataPool.h.
|
private |
Definition at line 50 of file DataPool.h.
typedef handle_t::pointer DataPool< VALUE, clear >::pointer |
Definition at line 53 of file DataPool.h.
typedef size_t DataPool< VALUE, clear >::size_type |
Definition at line 54 of file DataPool.h.
DataPool< VALUE, clear >::DataPool | ( | size_type | n = 0 | ) |
Constructors:
DataPool< VALUE, clear >::DataPool | ( | const EventContext & | ctx, |
size_type | n = 0 |
||
) |
DataPool< VALUE, clear >::DataPool | ( | SG::Arena * | arena, |
size_type | n = 0 |
||
) |
unsigned int DataPool< VALUE, clear >::allocated | ( | ) |
return size already allocated OK
iterator DataPool< VALUE, clear >::begin | ( | ) |
begin iterators over pool
const_iterator DataPool< VALUE, clear >::begin | ( | ) | const |
|
staticprivate |
unsigned int DataPool< VALUE, clear >::capacity | ( | ) |
return capacity of pool OK
iterator DataPool< VALUE, clear >::end | ( | ) |
the end() method will allow looping over only valid elements and not over ALL elements of the pool
const_iterator DataPool< VALUE, clear >::end | ( | ) | const |
void DataPool< VALUE, clear >::erase | ( | ) |
free all memory in the pool.
|
staticprivate |
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.
void DataPool< VALUE, clear >::prepareToAdd | ( | unsigned int | size | ) |
Prepare to add cached elements.
size | Additional 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
void DataPool< VALUE, clear >::reserve | ( | unsigned int | size | ) |
Set the desired capacity.
size | The 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.
void DataPool< VALUE, clear >::reset | ( | ) |
release all elements in the pool.
|
static |
typename of pool
|
private |
Definition at line 182 of file DataPool.h.
|
staticconstexprprivate |
minimum number of elements in pool
Definition at line 187 of file DataPool.h.
|
staticprivate |
Definition at line 184 of file DataPool.h.