ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
CxxUtils
Root
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$
12
13
14
#include "
CxxUtils/pointer_list.h
"
15
#include <algorithm>
16
17
18
namespace
CxxUtils
{
19
20
29
pointer_list_base::allocator::allocator
(
size_t
nelt
,
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
47
pointer_list_base::allocator::~allocator
()
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
62
void
pointer_list_base::allocator::refill
()
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
89
void
pointer_list_base::clear
()
90
{
91
if
(
m_head
)
92
m_insert
= &
m_head
->m_data[0];
93
m_size
= 0;
94
}
95
96
100
void
pointer_list_base::firstblock
()
101
{
102
m_head
=
getblock
();
103
m_insert
= &
m_head
->m_data[0];
104
}
105
106
111
void
pointer_list_base::nextblock
()
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
127
pointer_list_base::list_block
*
pointer_list_base::getblock
()
128
{
129
list_block
* b =
m_pool
.allocate();
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::allocator::m_end_mask
unsigned long m_end_mask
Mask for testing for an end pointer.
Definition
pointer_list.h:158
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::refill
void refill()
Allocate a new chunk of blocks.
Definition
pointer_list.cxx:62
CxxUtils::pointer_list_base::allocator::m_nblock
size_t m_nblock
Number of blocks per chunk.
Definition
pointer_list.h:146
CxxUtils::pointer_list_base::allocator::~allocator
~allocator()
Destructor. Deletes all blocks from this allocator.
Definition
pointer_list.cxx:47
CxxUtils::pointer_list_base::allocator::m_chunks
chunk * m_chunks
Most recent chunk allocated.
Definition
pointer_list.h:149
CxxUtils::pointer_list_base::allocator::m_nelt
size_t m_nelt
Number of elements per block (excluding the end-pointer).
Definition
pointer_list.h:143
CxxUtils::pointer_list_base::allocator::m_nchunks
size_t m_nchunks
Current number of allocated chunks.
Definition
pointer_list.h:155
CxxUtils::pointer_list_base::allocator::m_end_offs
unsigned long m_end_offs
Offset for testing for an end pointer.
Definition
pointer_list.h:161
CxxUtils::pointer_list_base::allocator::nelt
size_t nelt() const
Return the number of pointers per block (excluding the end-pointer).
CxxUtils::pointer_list_base::allocator::m_nthis
size_t m_nthis
Number of blocks allocated so far from that chunk.
Definition
pointer_list.h:152
CxxUtils::pointer_list_base::value_type
list_block::value_type value_type
The stored element type.
Definition
pointer_list.h:169
CxxUtils::pointer_list_base::m_head
list_block * m_head
The first block in the list.
Definition
pointer_list.h:191
CxxUtils::pointer_list_base::nextblock
void nextblock()
Extend the list with another block.
Definition
pointer_list.cxx:111
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::clear
void clear()
Erase the container.
Definition
pointer_list.cxx:89
CxxUtils::pointer_list_base::firstblock
void firstblock()
Allocate the first block of the list.
Definition
pointer_list.cxx:100
CxxUtils::pointer_list_base::m_size
size_t m_size
The current list size.
Definition
pointer_list.h:197
CxxUtils::pointer_list_base::m_pool
allocator & m_pool
The list allocator.
Definition
pointer_list.h:200
CxxUtils::pointer_list_base::getblock
list_block * getblock()
Allocate a new block.
Definition
pointer_list.cxx:127
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
CxxUtils::pointer_list_base::list_block
A single block in the list.
Definition
pointer_list.h:66
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).
CxxUtils::pointer_list_base::list_block::m_data
value_type m_data[1]
The elements.
Definition
pointer_list.h:75
Generated on
for ATLAS Offline Software by
1.17.0