ATLAS Offline Software
|
A fast way to store a variable-sized collection of pointers. More...
#include <pointer_list.h>
Classes | |
class | allocator |
Allocator for pointer_list , specialized for NELT . More... | |
class | iterator |
Forward iterator over the list. More... | |
Public Types | |
typedef pointer_list_base::value_type | value_type |
Stored value type. More... | |
typedef allocator | pool_type |
Public Member Functions | |
pointer_list (pool_type &pool) | |
Constructor. pool gives the allocator for this container. More... | |
iterator | begin () |
Iterator at the beginning of the container. More... | |
iterator | end () |
Iterator at the end of the container. More... | |
void | erase (iterator it) |
Erase one element. O(n) More... | |
void | push_back (value_type p) |
Add a new element to the end of the container. O(1) More... | |
size_t | size () const |
The current size of the container. O(1). More... | |
void | clear () |
Erase the container. More... | |
bool | empty () const |
Test to see if the container is empty. More... | |
Protected Member Functions | |
void | firstblock () |
Allocate the first block of the list. More... | |
void | nextblock () |
Extend the list with another block. More... | |
list_block * | getblock () |
Allocate a new block. More... | |
Protected Attributes | |
list_block * | m_head |
The first block in the list. More... | |
value_type * | m_insert |
The current insertion point in the list. More... | |
size_t | m_size |
The current list size. More... | |
allocator & | m_pool |
The list allocator. More... | |
A fast way to store a variable-sized collection of pointers.
If you're growing a variable-sized collection of things, all the STL containers have some performance issues. A std::vector needs to reallocate and copy its data as it grows. The use of variable-sized allocations also means that one cannot use the very efficient fixed-size memory allocators. A std::list incurs a separate memory allocation for each element, and, if the elements are pointers, has a substantial size overhead.
The class here is a compromise, which builds a list consisting of fixed-size chunks.
The operations supported are rather limited. We support forward iteration, push_back, and erase (though the latter can have O(n) complexity).
For best performance, we use our own allocator, an instance of which gets passed to the pointer_list
constructor. Memory is not freed until the allocator is destroyed.
This class is templated on the number of elements stored per block. This must be one less than a power of two.
Definition at line 240 of file pointer_list.h.
typedef allocator CxxUtils::pointer_list< NELT >::pool_type |
Definition at line 315 of file pointer_list.h.
typedef pointer_list_base::value_type CxxUtils::pointer_list< NELT >::value_type |
Stored value type.
Definition at line 245 of file pointer_list.h.
CxxUtils::pointer_list< NELT >::pointer_list | ( | pool_type & | pool | ) |
Constructor. pool
gives the allocator for this container.
iterator CxxUtils::pointer_list< NELT >::begin | ( | ) |
Iterator at the beginning of the container.
|
inherited |
|
inherited |
Test to see if the container is empty.
iterator CxxUtils::pointer_list< NELT >::end | ( | ) |
Iterator at the end of the container.
void CxxUtils::pointer_list< NELT >::erase | ( | iterator | it | ) |
Erase one element. O(n)
|
protectedinherited |
|
protectedinherited |
Allocate a new block.
Definition at line 127 of file pointer_list.cxx.
|
protectedinherited |
Extend the list with another block.
m_insert
should be at the end of the last block.
Definition at line 111 of file pointer_list.cxx.
|
inherited |
Add a new element to the end of the container. O(1)
|
inherited |
The current size of the container. O(1).
|
protectedinherited |
The first block in the list.
Definition at line 191 of file pointer_list.h.
|
protectedinherited |
The current insertion point in the list.
Definition at line 194 of file pointer_list.h.
|
protectedinherited |
The list allocator.
Definition at line 200 of file pointer_list.h.
|
protectedinherited |
The current list size.
Definition at line 197 of file pointer_list.h.