2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
5 //-----------------------------------------------------------
6 // .icc file for DataPool
7 //-----------------------------------------------------------
10 #include "GaudiKernel/System.h"
13 #define DATAPOOL_T template <typename VALUE, DataPoolClearFuncPtr_t<VALUE> clear>
15 const typename DataPool<VALUE, clear>::alloc_t::Params DataPool<VALUE, clear>::s_params
16 = DataPool<VALUE, clear>::initParams();
20 # pragma GCC diagnostic push
21 # pragma GCC diagnostic ignored "-Waddress"
24 typename DataPool<VALUE, clear>::alloc_t::Params DataPool<VALUE, clear>::initParams()
26 typename alloc_t::Params params = alloc_t::initParams<VALUE> (s_minRefCount);
27 if (clear != nullptr) {
28 params.clear = callClear;
33 # pragma GCC diagnostic pop
38 void DataPool<VALUE, clear>::callClear (SG::ArenaAllocatorBase::pointer p)
40 clear (reinterpret_cast<VALUE*> (p));
44 //-----------------------------------------------------------
47 DataPool<VALUE, clear>::DataPool(size_type n /*= 0*/)
48 : m_handle (&s_params)
51 m_handle.reserve (std::max (n, s_minRefCount));
55 DataPool<VALUE, clear>::DataPool(const EventContext& ctx,
57 : m_handle (static_cast<SG::ArenaHeader*>(nullptr), ctx, &s_params)
60 m_handle.reserve (std::max (n, s_minRefCount));
64 DataPool<VALUE, clear>::DataPool(SG::Arena* arena,
66 : m_handle (arena, &s_params)
69 m_handle.reserve (std::max (n, s_minRefCount));
72 //-----------------------------------------------------------
73 /// release all elements in the pool.
75 void DataPool<VALUE, clear>::reset()
80 /// free all memory in the pool.
82 void DataPool<VALUE, clear>::erase()
86 //-----------------------------------------------------------
87 // reserve space for the pool
88 // allocated elements will not be deleted.
91 void DataPool<VALUE, clear>::reserve(unsigned int size)
93 m_handle.reserve (size);
98 void DataPool<VALUE, clear>::prepareToAdd(unsigned int size)
100 if (this->capacity() - this->allocated() < size) {
101 this->reserve(this->allocated() + size);
106 unsigned int DataPool<VALUE, clear>::capacity()
108 return m_handle.stats().elts.total;
112 unsigned int DataPool<VALUE, clear>::allocated()
114 return m_handle.stats().elts.inuse;
118 //-----------------------------------------------------------
119 /// begin iterators over pool
121 typename DataPool<VALUE, clear>::iterator DataPool<VALUE, clear>::begin()
123 return iterator (m_handle.begin());
127 typename DataPool<VALUE, clear>::const_iterator DataPool<VALUE, clear>::begin() const
129 return const_Iterator (m_handle.begin());
132 //-----------------------------------------------------------
133 /// the end() method will allow looping over only valid elements
134 /// and not over ALL elements of the pool
137 typename DataPool<VALUE, clear>::iterator DataPool<VALUE, clear>::end()
139 return iterator (m_handle.end());
143 typename DataPool<VALUE, clear>::const_iterator DataPool<VALUE, clear>::end() const {
144 return const_iterator (m_handle.end());
147 //-----------------------------------------------------------
150 const std::string& DataPool<VALUE, clear>::typeName() {
151 static std::string name = System::typeinfoName (typeid (VALUE));
155 //-----------------------------------------------------------
156 /// obtain the next available element in pool by pointer
157 /// pool is resized if reached its limit
160 typename DataPool<VALUE, clear>::pointer DataPool<VALUE, clear>::nextElementPtr()
162 return m_handle.allocate();