ATLAS Offline Software
Loading...
Searching...
No Matches
ArenaHandle.icc
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3*/
4
5// $Id: ArenaHandle.icc 470529 2011-11-24 23:54:22Z ssnyder $
6/**
7 * @file AthAllocators/ArenaHandle.icc
8 * @author scott snyder
9 * @date May 2007
10 * @brief User interface for allocating memory.
11 * Inline and template implementations.
12 */
13
14
15namespace SG {
16
17
18/**
19 * @brief Constructor, passing in an index. (For internal/testing use.)
20 * @param header The group of Arenas which this Handle may reference.
21 * May be null to select the global default.
22 * @param index The index of this Handle's Allocator type.
23 */
24template <class T, class ALLOC>
25ArenaHandle<T, ALLOC>::ArenaHandle (ArenaHeader* header,
26 size_t index)
27 : Base (header, index)
28{
29}
30
31
32/**
33 * @brief Constructor, passing in an optional parameter set.
34 * @param params Parameters to pass to the Allocator,
35 * or nullptr to use the defaults.
36 */
37template <class T, class ALLOC>
38ArenaHandle<T, ALLOC>::ArenaHandle
39 (const typename ALLOC::Params* params /*= nullptr*/)
40 : Base (static_cast<SG::ArenaHeader*>(nullptr),
41 Base::template makeIndex<ArenaHandle, defaultParams_t> (params))
42{
43}
44
45
46/**
47 * @brief Constructor, passing in a Header and an optional parameter set.
48 * @param header The group of Arenas which this Handle may reference.
49 * May be null to select the global default.
50 * @param params Parameters to pass to the Allocator,
51 * or nullptr to use the defaults.
52 */
53template <class T, class ALLOC>
54ArenaHandle<T, ALLOC>::ArenaHandle
55 (ArenaHeader* header,
56 const typename ALLOC::Params* params /*= nullptr*/)
57 : Base (header,
58 Base::template makeIndex<ArenaHandle, defaultParams_t> (params))
59{
60}
61
62
63/**
64 * @brief Constructor, passing in a Header, context, and an optional parameter set.
65 * @param header The group of Arenas which this Handle may reference.
66 * May be null to select the global default.
67 * @param ctx Event context identifying the event slot.
68 * @param params Parameters to pass to the Allocator,
69 * or nullptr to use the defaults.
70 */
71template <class T, class ALLOC>
72ArenaHandle<T, ALLOC>::ArenaHandle
73 (ArenaHeader* header,
74 const EventContext& ctx,
75 const typename ALLOC::Params* params /*= nullptr*/)
76 : Base (header,
77 ctx,
78 Base::template makeIndex<ArenaHandle, defaultParams_t> (params))
79{
80}
81
82
83/**
84 * @brief Constructor, passing in an Arena and an optional parameter set.
85 * @param arena The Arena in which to create the Allocator.
86 * @param params Parameters to pass to the Allocator,
87 * or nullptr to use the defaults.
88 */
89template <class T, class ALLOC>
90ArenaHandle<T, ALLOC>::ArenaHandle
91 (Arena* arena,
92 const typename ALLOC::Params* params /*= nullptr*/)
93 : Base (arena,
94 Base::template makeIndex<ArenaHandle, defaultParams_t> (params))
95{
96}
97
98
99/**
100 * @brief Allocate a new element.
101 *
102 * The element's constructor will not be called; thus, the memory
103 * is returned as a @c void*.
104 *
105 * This is on the fast path for element allocation, so keep it small
106 * and inline.
107 */
108template <class T, class ALLOC>
109inline
110void* ArenaHandle<T, ALLOC>::allocate()
111{
112 return this->allocator()->allocate();
113}
114
115
116/**
117 * @brief Internal helper: create a new Allocator instance.
118 * @param params The parameters for the Allocator.
119 */
120template <class T, class ALLOC>
121std::unique_ptr<ArenaAllocatorBase> ArenaHandle<T, ALLOC>::makeAllocator
122 (const typename ALLOC::Params& params)
123{
124 typename ALLOC::Params newparams = params;
125
126 // We don't call the element constructor.
127 newparams.constructor = 0;
128
129 // The destructor is called when we free an element --- not when
130 // we return it to the system.
131 newparams.clear = newparams.destructor;
132 newparams.destructor = 0;
133
134 // We can't skip running the destructor.
135 newparams.mustClear = true;
136
137 // We can't call the destructor twice.
138 newparams.canReclear = false;
139
140 // If we need a link, it can overlap the element.
141 newparams.eltSize = std::max (sizeof(T), newparams.minSize);
142 newparams.linkOffset = 0;
143
144 // Make the Allocator.
145 return std::make_unique <ALLOC> (newparams);
146}
147
148
149} // namespace SG