ATLAS Offline Software
ArenaPoolAllocator.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 /**
5  * @file AthAllocators/ArenaPoolAllocator.icc
6  * @author scott snyder
7  * @date May 2007
8  * @brief Pool-based allocator.
9  * Inline implementations.
10  */
11 
12 
13 namespace SG {
14 
15 
16 /**
17  * @brief Default constructor.
18  */
19 inline
20 ArenaPoolAllocator::iterator::iterator()
21  : iterator::iterator_adaptor_ (0),
22  m_block (0)
23 {
24 }
25 
26 
27 /**
28  * @brief Constructor.
29  * @param p Pointer to the element.
30  * @param block Block containing the element.
31  */
32 inline
33 ArenaPoolAllocator::iterator::iterator (pointer p, ArenaBlock* block)
34  : iterator::iterator_adaptor_ (p),
35  m_block (block)
36 {
37 }
38 
39 
40 /**
41  * @brief Default constructor.
42  */
43 inline
44 ArenaPoolAllocator::const_iterator::const_iterator ()
45  : const_iterator::iterator_adaptor_ (0),
46  m_block (0)
47 {
48 }
49 
50 
51 /**
52  * @brief Constructor.
53  * @param p Pointer to the element.
54  * @param block Block containing the element.
55  */
56 inline
57 ArenaPoolAllocator::const_iterator::const_iterator (pointer p,
58  const ArenaBlock* block)
59  : const_iterator::iterator_adaptor_ (p),
60  m_block (block)
61 {
62 }
63 
64 
65 /**
66  * @brief Constructor from @c iterator.
67  * @param it The iterator to copy.
68  */
69 inline
70 ArenaPoolAllocator::const_iterator::const_iterator (const iterator& it)
71  : const_iterator::iterator_adaptor_ (it.base_reference()),
72  m_block (it.m_block)
73 {
74 }
75 
76 
77 /**
78  * @brief Allocate a new element.
79  *
80  * The fast path of this will be completely inlined.
81  */
82 inline
83 ArenaPoolAllocator::pointer ArenaPoolAllocator::allocate()
84 {
85  // If there are no free elements get more.
86  if (m_ptr >= m_end)
87  refill();
88 
89  // Take the first free element.
90  pointer ret = m_ptr;
91  m_ptr = m_ptr + m_params.eltSize;
92 
93  // Update statistics.
94  ++m_stats.elts.inuse;
95 
96  return ret;
97 }
98 
99 
100 } // namespace SG