2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
5 * @file AthAllocators/ArenaAllocatorBase.icc
8 * @brief Common base class for arena allocator classes.
9 * Inline/template implementations.
17 * @brief Make a constructor function pointer for a non-trivial constructor.
20 ArenaAllocatorBase::func_t*
21 ArenaAllocatorBase::makeConstructor (const std::false_type&)
23 return &construct_fcn<T>;
28 * @brief Make a constructor function pointer for a trivial constructor.
31 ArenaAllocatorBase::func_t*
32 ArenaAllocatorBase::makeConstructor (const std::true_type&)
39 * @brief Make a constructor function pointer for a non-trivial destructor.
42 ArenaAllocatorBase::func_t*
43 ArenaAllocatorBase::makeDestructor (const std::false_type&)
45 return &destroy_fcn<T>;
50 * @brief Make a constructor function pointer for a trivial destructor.
53 ArenaAllocatorBase::func_t*
54 ArenaAllocatorBase::makeDestructor (const std::true_type&)
61 * @brief Make a function pointer for a @c clear function.
64 ArenaAllocatorBase::func_t*
65 ArenaAllocatorBase::makeClear (const std::false_type&)
72 * @brief Make a dummy @c clear function pointer.
75 ArenaAllocatorBase::func_t*
76 ArenaAllocatorBase::makeClear (const std::true_type&)
83 * @brief Call @c T's default constructor on the object at @c p.
84 * @param p The object on which to run the constructor.
87 void ArenaAllocatorBase::construct_fcn (pointer p)
94 * @brief Call @c T's destructor on the object at @c p.
95 * @param p The object on which to run the destructor.
98 void ArenaAllocatorBase::destroy_fcn (pointer p)
100 reinterpret_cast<T*>(p)->~T();
105 * @brief Call @c T::clear on the object at @c p.
106 * @param p The object on which to run the @c clear.
108 template <typename T>
109 void ArenaAllocatorBase::clear_fcn (pointer p)
111 reinterpret_cast<T*>(p)->clear();
116 * @brief Constructor.
117 * @param nblock Value to set in the parameters structure for the
118 * number of elements to allocate per block.
119 * @param name Value to set in the parameters structure for the
122 template <typename T, bool clear, bool no_ctor, bool no_dtor>
123 ArenaAllocatorBase::initParams<T, clear, no_ctor, no_dtor>::initParams
124 (size_t nblock /*=1000*/,
125 const std::string& name /*= ""*/)
133 * @brief Return an initialized parameters structure.
135 template <typename T, bool clear, bool no_ctor, bool no_dtor>
136 ArenaAllocatorBase::Params
137 ArenaAllocatorBase::initParams<T, clear, no_ctor, no_dtor>::params() const
141 // Fill in the parameters that were passed to our constructor.
142 params.nblock = m_nblock;
143 params.name = m_name;
145 // We're not setting up a link.
146 params.linkOffset = 0;
147 params.eltSize = sizeof (T);
150 // Defaults for these.
151 params.canReclear = true;
152 params.mustClear = false;
154 // Set up the constructor/destructor.
155 // We want the pointers to be null if they're trivial.
157 makeConstructor<T> (::std::integral_constant<bool,
158 ::std::is_trivially_constructible<T>::value ||
161 makeDestructor<T> (::std::integral_constant<bool,
162 ::std::is_trivially_destructible<T>::value ||
165 // Set up the clear function --- only if the flag is set!
166 params.clear = makeClear<T> (::std::integral_constant<bool, !clear>());