CxxUtils::pointer_list< NELT > Class Template Reference

A fast way to store a variable-sized collection of pointers. More...

#include <pointer_list.h>

Inheritance diagram for CxxUtils::pointer_list< NELT >:
CxxUtils::pointer_list_base

List of all members.

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.
typedef allocator pool_type
 Alias for allocator.

Public Member Functions

 pointer_list (pool_type &pool)
 Constructor. pool gives the allocator for this container.
iterator begin ()
 Iterator at the beginning of the container.
iterator end ()
 Iterator at the end of the container.
void erase (iterator it)
 Erase one element. O(n).

Detailed Description

template<size_t NELT = 15>
class CxxUtils::pointer_list< NELT >

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.


Constructor & Destructor Documentation

template<size_t NELT>
CxxUtils::pointer_list< NELT >::pointer_list ( pool_type pool  )  [inline]

Constructor. pool gives the allocator for this container.

Constructor.

Parameters:
pool The allocator for this container.

Member Function Documentation

template<size_t NELT>
void CxxUtils::pointer_list< NELT >::erase ( iterator  it  )  [inline]

Erase one element. O(n).

Parameters:
it The element to erase.

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 15 Apr 2017 for RootCore Packages by  doxygen 1.6.1