ATLAS Offline Software
pointer_list.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // $Id$
14 #include "CxxUtils/pointer_list.h"
15 #include <algorithm>
16 
17 
18 namespace CxxUtils {
19 
20 
30  size_t nblock,
31  unsigned long end_mask,
32  unsigned long end_offs)
33  : m_nelt (nelt),
34  m_nblock (nblock),
35  m_chunks (0),
36  m_nthis (nblock),
37  m_nchunks (0),
38  m_end_mask (end_mask),
39  m_end_offs (end_offs)
40 {
41 }
42 
43 
48 {
49  // Loop over the chunks, deleting each one.
50  chunk* ch = m_chunks;
51  while (ch) {
52  chunk* next = ch->m_next;
53  delete [] reinterpret_cast<char*> (ch);
54  ch = next;
55  }
56 }
57 
58 
63 {
64  char* p = new char
65  [(sizeof(chunk) + m_nblock*list_block::size(m_nelt)) +
66  list_block::size(m_nelt)-1];
67  chunk* ch = reinterpret_cast<chunk*> (p);
68 
69  // Align.
70  unsigned long pp = reinterpret_cast<unsigned long> (ch+1);
71  pp = (pp + m_end_mask) & ~m_end_mask;
72  ch->m_blocks = reinterpret_cast<list_block*> (pp);
73 
74  ch->m_next = m_chunks;
75  m_chunks = ch;
76  ++m_nchunks;
77 
78  // No blocks allocated so far from this chunk.
79  m_nthis = 0;
80 }
81 
82 
90 {
91  if (m_head)
92  m_insert = &m_head->m_data[0];
93  m_size = 0;
94 }
95 
96 
101 {
102  m_head = getblock();
103  m_insert = &m_head->m_data[0];
104 }
105 
106 
112 {
113  // There may be one already allocated. Use it if so.
114  list_block* newblock =
115  reinterpret_cast<list_block*> (*m_insert);
116  if (!newblock) {
117  newblock = getblock();
118  *m_insert = newblock;
119  }
120  m_insert = &newblock->m_data[0];
121 }
122 
123 
128 {
130  size_t maxndx = m_pool.nelt();
131 
132  // Make sure only the last element has the sentinel bit set.
133  std::fill (b->m_data, b->m_data + maxndx, value_type());
134  b->m_data[maxndx] = 0;
135 
136  return b;
137 }
138 
139 
140 } // namespace CxxUtils
141 
CxxUtils::pointer_list_base::m_head
list_block * m_head
The first block in the list.
Definition: pointer_list.h:191
sendEI_SPB.ch
ch
Definition: sendEI_SPB.py:35
CxxUtils::pointer_list_base::clear
void clear()
Erase the container.
Definition: pointer_list.cxx:89
CxxUtils::pointer_list_base::list_block::m_data
value_type m_data[1]
The elements.
Definition: pointer_list.h:75
CxxUtils::pointer_list_base::list_block
A single block in the list.
Definition: pointer_list.h:66
CxxUtils::pointer_list_base::m_insert
value_type * m_insert
The current insertion point in the list.
Definition: pointer_list.h:194
CxxUtils::pointer_list_base::allocator::refill
void refill()
Allocate a new chunk of blocks.
Definition: pointer_list.cxx:62
CxxUtils::pointer_list_base::nextblock
void nextblock()
Extend the list with another block.
Definition: pointer_list.cxx:111
CxxUtils::pointer_list_base::getblock
list_block * getblock()
Allocate a new block.
Definition: pointer_list.cxx:127
CxxUtils::pointer_list_base::m_pool
allocator & m_pool
The list allocator.
Definition: pointer_list.h:200
CxxUtils::pointer_list_base::m_size
size_t m_size
The current list size.
Definition: pointer_list.h:197
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
CxxUtils::pointer_list_base::allocator::nelt
size_t nelt() const
Return the number of pointers per block (excluding the end-pointer).
fillPileUpNoiseLumi.next
next
Definition: fillPileUpNoiseLumi.py:52
CxxUtils::pointer_list_base::allocator::allocator
allocator(size_t nelt, size_t nblock, unsigned long end_mask, unsigned long end_offs)
Constructor.
Definition: pointer_list.cxx:29
CxxUtils::pointer_list_base::allocator::allocate
list_block * allocate()
Allocate a new block.
CxxUtils
Definition: aligned_vector.h:29
pointer_list.h
A fast way to store a variable-sized collection of pointers.
CxxUtils::pointer_list_base::allocator::chunk
One memory allocation chunk.
Definition: pointer_list.h:134
fill
void fill(H5::Group &out_file, size_t iterations)
Definition: test-hdf5-writer.cxx:95
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
CxxUtils::pointer_list_base::firstblock
void firstblock()
Allocate the first block of the list.
Definition: pointer_list.cxx:100
value_type
Definition: EDM_MasterSearch.h:11
CxxUtils::pointer_list_base::allocator::~allocator
~allocator()
Destructor. Deletes all blocks from this allocator.
Definition: pointer_list.cxx:47
CxxUtils::pointer_list_base::list_block::size
static size_t size(size_t nelt)
Size in bytes of a block holding nelt elements (excluding the end-pointer).