![]() |
ATLAS Offline Software
|
a typed memory pool that saves time spent allocation small object. 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: | |
| DataPool (const EventContext &ctx, size_type n=0) | |
| DataPool (SG::Arena *arena, size_type n=0) | |
| void | reset () |
| release all elements in the pool. | |
| void | erase () |
| free all memory in the pool. | |
| void | reserve (unsigned int size) |
| Set the desired capacity. | |
| void | prepareToAdd (unsigned int size) |
| Prepare to add cached elements. | |
| unsigned int | capacity () |
| return capacity of pool OK | |
| unsigned int | allocated () |
| return size already allocated OK | |
| iterator | begin () |
| begin iterators over pool | |
| const_iterator | begin () const |
| iterator | end () |
| the end() method will allow looping over only valid elements and not over ALL elements of the pool | |
| 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. | |
Static Public Member Functions | |
| static const std::string & | typeName () |
| typename of pool | |
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 | |
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 functional to be called on an object when it is returned to the pool. This can be used to reset the state, release memory, etc. The functional should have a static method clear() which takes a pointer to the object to clean. [static operator() is only available as of C++23] Also be aware that the CLEAR argument will have an effect only for the first DataPool object to be created for a given VALUE.
Definition at line 62 of file DataPool.h.
|
private |
Definition at line 65 of file DataPool.h.
Definition at line 66 of file DataPool.h.
| typedef handle_t::pointer DataPool< VALUE, CLEAR >::pointer |
Definition at line 69 of file DataPool.h.
Definition at line 70 of file DataPool.h.
| DataPool< VALUE, CLEAR >::DataPool | ( | size_type | n = 0 | ) |
Constructors:
| DataPool< VALUE, CLEAR >::DataPool | ( | const EventContext & | ctx, |
| size_type | n = 0 ) |
| const_iterator DataPool< VALUE, CLEAR >::begin | ( | ) | const |
|
staticprivate |
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 |
|
staticprivate |
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.
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
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.
minimum number of elements in pool
Definition at line 203 of file DataPool.h.
|
staticprivate |
Definition at line 200 of file DataPool.h.