2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
5 // $Id: ArenaHeapAllocator.icc 470529 2011-11-24 23:54:22Z ssnyder $
7 * @file AthAllocators/ArenaPoolAllocator.icc
10 * @brief Heap-based allocator.
11 * Inline and template implementations.
19 * @brief Constructor for parameters helper.
20 * @param nblock Value to set in the parameters structure for the
21 * number of elements to allocate per block.
22 * @param name Value to set in the parameters structure for the
25 template <typename T, bool clear, bool no_ctor, bool no_dtor>
26 ArenaHeapAllocator::initParams<T, clear, no_ctor, no_dtor>::
27 initParams (size_t nblock /*=1000*/, const std::string& name /*=""*/)
34 * @brief Return an initialized parameters structure.
36 template <typename T, bool clear, bool no_ctor, bool no_dtor>
37 ArenaAllocatorBase::Params
38 ArenaHeapAllocator::initParams<T, clear, no_ctor, no_dtor>::params() const
40 // Do the base class stuff.
41 Params p = Base::operator ArenaAllocatorBase::Params();
43 // Allow space for an extra pointer.
48 p.eltSize = sizeof (Dummy);
49 Dummy* dummy = (Dummy*)0x1234;
50 // nb. offsetof gives warnings here because the struct is not standard-layout.
51 p.linkOffset = reinterpret_cast<char*>(&dummy->y) - reinterpret_cast<char*>(dummy);
53 // Need to allow at least enough space for a pointer.
54 p.minSize = sizeof (pointer);
61 * @brief Allocate a new element.
63 * The fast path of this will be completely inlined.
66 ArenaHeapAllocator::pointer ArenaHeapAllocator::allocate()
69 pointer ret = m_freeptr;
71 m_freeptr = link (ret);
79 * @brief Free an element.
80 * @param p The element to be freed.
82 * @c clear() will be called on the element at this point,
83 * if it has been defined.
86 void ArenaHeapAllocator::free (pointer p)
98 * @brief Return a reference to the link for an element.
99 * @param p The element.
102 ArenaHeapAllocator::pointer& ArenaHeapAllocator::link (pointer p) const
104 return *reinterpret_cast<pointer*> (p + m_params.linkOffset);