ATLAS Offline Software
Loading...
Searching...
No Matches
ArenaAllocatorBase.icc
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4/**
5 * @file AthAllocators/ArenaAllocatorBase.icc
6 * @author scott snyder
7 * @date May 2007
8 * @brief Common base class for arena allocator classes.
9 * Inline/template implementations.
10 */
11
12
13namespace SG {
14
15
16/**
17 * @brief Make a constructor function pointer for a non-trivial constructor.
18 */
19template <class T>
20ArenaAllocatorBase::func_t*
21ArenaAllocatorBase::makeConstructor (const std::false_type&)
22{
23 return &construct_fcn<T>;
24}
25
26
27/**
28 * @brief Make a constructor function pointer for a trivial constructor.
29 */
30template <class T>
31ArenaAllocatorBase::func_t*
32ArenaAllocatorBase::makeConstructor (const std::true_type&)
33{
34 return 0;
35}
36
37
38/**
39 * @brief Make a constructor function pointer for a non-trivial destructor.
40 */
41template <class T>
42ArenaAllocatorBase::func_t*
43ArenaAllocatorBase::makeDestructor (const std::false_type&)
44{
45 return &destroy_fcn<T>;
46}
47
48
49/**
50 * @brief Make a constructor function pointer for a trivial destructor.
51 */
52template <class T>
53ArenaAllocatorBase::func_t*
54ArenaAllocatorBase::makeDestructor (const std::true_type&)
55{
56 return 0;
57}
58
59
60/**
61 * @brief Make a function pointer for a @c clear function.
62 */
63template <class T>
64ArenaAllocatorBase::func_t*
65ArenaAllocatorBase::makeClear (const std::false_type&)
66{
67 return &clear_fcn<T>;
68}
69
70
71/**
72 * @brief Make a dummy @c clear function pointer.
73 */
74template <class T>
75ArenaAllocatorBase::func_t*
76ArenaAllocatorBase::makeClear (const std::true_type&)
77{
78 return 0;
79}
80
81
82/**
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.
85 */
86template <typename T>
87void ArenaAllocatorBase::construct_fcn (pointer p)
88{
89 new(p) T;
90}
91
92
93/**
94 * @brief Call @c T's destructor on the object at @c p.
95 * @param p The object on which to run the destructor.
96 */
97template <typename T>
98void ArenaAllocatorBase::destroy_fcn (pointer p)
99{
100 reinterpret_cast<T*>(p)->~T();
101}
102
103
104/**
105 * @brief Call @c T::clear on the object at @c p.
106 * @param p The object on which to run the @c clear.
107 */
108template <typename T>
109void ArenaAllocatorBase::clear_fcn (pointer p)
110{
111 reinterpret_cast<T*>(p)->clear();
112}
113
114
115/**
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
120 * allocator name.
121 */
122template <typename T, bool clear, bool no_ctor, bool no_dtor>
123ArenaAllocatorBase::initParams<T, clear, no_ctor, no_dtor>::initParams
124 (size_t nblock /*=1000*/,
125 const std::string& name /*= ""*/)
126 : m_nblock (nblock),
127 m_name (name)
128{
129}
130
131
132/**
133 * @brief Return an initialized parameters structure.
134 */
135template <typename T, bool clear, bool no_ctor, bool no_dtor>
136ArenaAllocatorBase::Params
137ArenaAllocatorBase::initParams<T, clear, no_ctor, no_dtor>::params() const
138{
139 Params params;
140
141 // Fill in the parameters that were passed to our constructor.
142 params.nblock = m_nblock;
143 params.name = m_name;
144
145 // We're not setting up a link.
146 params.linkOffset = 0;
147 params.eltSize = sizeof (T);
148 params.minSize = 1;
149
150 // Defaults for these.
151 params.canReclear = true;
152 params.mustClear = false;
153
154 // Set up the constructor/destructor.
155 // We want the pointers to be null if they're trivial.
156 params.constructor =
157 makeConstructor<T> (::std::integral_constant<bool,
158 ::std::is_trivially_constructible<T>::value ||
159 no_ctor>());
160 params.destructor =
161 makeDestructor<T> (::std::integral_constant<bool,
162 ::std::is_trivially_destructible<T>::value ||
163 no_dtor>());
164
165 // Set up the clear function --- only if the flag is set!
166 params.clear = makeClear<T> (::std::integral_constant<bool, !clear>());
167
168 return params;
169}
170
171
172} // namespace SG