2 Copyright (C) 2002-2017 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 p.linkOffset = (char*)&dummy->y - (char*)dummy;
52 // Need to allow at least enough space for a pointer.
53 p.minSize = sizeof (pointer);
60 * @brief Allocate a new element.
62 * The fast path of this will be completely inlined.
65 ArenaHeapAllocator::pointer ArenaHeapAllocator::allocate()
68 pointer ret = m_freeptr;
70 m_freeptr = link (ret);
78 * @brief Free an element.
79 * @param p The element to be freed.
81 * @c clear() will be called on the element at this point,
82 * if it has been defined.
85 void ArenaHeapAllocator::free (pointer p)
97 * @brief Return a reference to the link for an element.
98 * @param p The element.
101 ArenaHeapAllocator::pointer& ArenaHeapAllocator::link (pointer p) const
103 return *reinterpret_cast<pointer*> (p + m_params.linkOffset);