2 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
5 // $Id: ArenaCachingHandle.icc 470529 2011-11-24 23:54:22Z ssnyder $
7 * @file AthAllocators/ArenaCachingHandle.icc
10 * @brief User interface for allocating memory that caches constructed objects.
11 * Inline and template implementations.
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.
24 template <class T, class ALLOC>
25 ArenaCachingHandle<T, ALLOC>::ArenaCachingHandle (ArenaHeader* header,
27 : Base (header, index)
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.
37 template <class T, class ALLOC>
38 ArenaCachingHandle<T, ALLOC>::ArenaCachingHandle
39 (const typename ALLOC::Params* params /*= nullptr*/)
40 : Base (static_cast<ArenaHeader*>(nullptr),
41 Base::template makeIndex<ArenaCachingHandle, defaultParams_t> (params))
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.
53 template <class T, class ALLOC>
54 ArenaCachingHandle<T, ALLOC>::ArenaCachingHandle
56 const typename ALLOC::Params* params /*=nullptr */)
58 Base::template makeIndex<ArenaCachingHandle, defaultParams_t> (params))
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.
71 template <class T, class ALLOC>
72 ArenaCachingHandle<T, ALLOC>::ArenaCachingHandle
74 const EventContext& ctx,
75 const typename ALLOC::Params* params /*= nullptr */)
78 Base::template makeIndex<ArenaCachingHandle, defaultParams_t> (params))
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.
89 template <class T, class ALLOC>
90 ArenaCachingHandle<T, ALLOC>::ArenaCachingHandle
92 const typename ALLOC::Params* params /*= nullptr */)
94 Base::template makeIndex<ArenaCachingHandle, defaultParams_t> (params))
100 * @brief Allocate a new element.
102 * This returns an already-initialized element.
104 * This is on the fast path for element allocation, so keep it small
107 template <class T, class ALLOC>
109 typename ArenaCachingHandle<T, ALLOC>::pointer
110 ArenaCachingHandle<T, ALLOC>::allocate()
112 return reinterpret_cast<pointer> (this->allocator()->allocate());
117 * @brief Internal helper: create a new Allocator instance.
118 * @param params The parameters for the Allocator.
120 template <class T, class ALLOC>
121 std::unique_ptr<ArenaAllocatorBase> ArenaCachingHandle<T, ALLOC>::makeAllocator
122 (const typename ALLOC::Params& params)
124 return std::make_unique<ALLOC> (params);