LLVM: llvm::PagedVector< T, PageSize > Class Template Reference (original) (raw)

A vector that allocates memory in pages. More...

#include "[llvm/ADT/PagedVector.h](PagedVector%5F8h%5Fsource.html)"

Public Types
using value_type = T
Public Member Functions
PagedVector ()
Default constructor.
PagedVector (BumpPtrAllocator *A)
~PagedVector ()
PagedVector (const PagedVector &)=delete
PagedVector (PagedVector &&)=delete
PagedVector & operator= (const PagedVector &)=delete
PagedVector & operator= (PagedVector &&)=delete
T & operator[] (size_t Index) const
Look up an element at position Index.
size_t capacity () const
Return the capacity of the vector.
size_t size () const
Return the size of the vector.
void resize (size_t NewSize)
Resize the vector.
bool empty () const
void clear ()
Clear the vector, i.e.
MaterializedIterator materialized_begin () const
Iterators over the materialized elements of the vector.
MaterializedIterator materialized_end () const
llvm::iterator_range< MaterializedIterator > materialized () const

template<typename T, size_t PageSize = 1024 / sizeof(T)>
class llvm::PagedVector< T, PageSize >

A vector that allocates memory in pages.

Order is kept, but memory is allocated only when one element of the page is accessed. This introduces a level of indirection, but it is useful when you have a sparsely initialised vector where the full size is allocated upfront.

As a side effect the elements are initialised later than in a normal vector. On the first access to one of the elements of a given page, all the elements of the page are initialised. This also means that the elements of the page are initialised beyond the size of the vector.

Similarly on destruction the elements are destroyed only when the page is not needed anymore, delaying invoking the destructor of the elements.

Notice that this has iterators only on materialized elements. This is deliberately done under the assumption you would dereference the elements while iterating, therefore materialising them and losing the gains in terms of memory usage this container provides. If you have such a use case, you probably want to use a normal std::vector or a llvm::SmallVector.

Definition at line 42 of file PagedVector.h.

value_type

template<typename T, size_t PageSize = 1024 / sizeof(T)>

template<typename T, size_t PageSize = 1024 / sizeof(T)>

PagedVector() [2/4]

template<typename T, size_t PageSize = 1024 / sizeof(T)>

~PagedVector()

template<typename T, size_t PageSize = 1024 / sizeof(T)>

PagedVector() [3/4]

template<typename T, size_t PageSize = 1024 / sizeof(T)>

PagedVector() [4/4]

template<typename T, size_t PageSize = 1024 / sizeof(T)>

capacity()

template<typename T, size_t PageSize = 1024 / sizeof(T)>

Return the capacity of the vector.

I.e. the maximum size it can be expanded to with the resize method without allocating more pages.

Definition at line 99 of file PagedVector.h.

References PageSize.

clear()

template<typename T, size_t PageSize = 1024 / sizeof(T)>

empty()

template<typename T, size_t PageSize = 1024 / sizeof(T)>

materialized()

template<typename T, size_t PageSize = 1024 / sizeof(T)>

materialized_begin()

template<typename T, size_t PageSize = 1024 / sizeof(T)>

Iterators over the materialized elements of the vector.

This includes all the elements belonging to allocated pages, even if they have not been accessed yet. It's enough to access one element of a page to materialize all the elements of the page.

Definition at line 244 of file PagedVector.h.

References PageSize.

Referenced by materialized().

materialized_end()

template<typename T, size_t PageSize = 1024 / sizeof(T)>

operator=() [1/2]

template<typename T, size_t PageSize = 1024 / sizeof(T)>

operator=() [2/2]

template<typename T, size_t PageSize = 1024 / sizeof(T)>

operator[]()

template<typename T, size_t PageSize = 1024 / sizeof(T)>

Look up an element at position Index.

If the associated page is not filled, it will be filled with default constructed elements.

Definition at line 82 of file PagedVector.h.

References assert(), LLVM_UNLIKELY, PageSize, and T.

resize()

template<typename T, size_t PageSize = 1024 / sizeof(T)>

Resize the vector.

Notice that the constructor of the elements will not be invoked until an element of a given page is accessed, at which point all the elements of the page will be constructed.

If the new size is smaller than the current size, the elements of the pages that are not needed anymore will be destroyed, however, elements of the last page will not be destroyed.

For these reason the usage of this vector is discouraged if you rely on the construction / destructor of the elements to be invoked.

Definition at line 116 of file PagedVector.h.

References clear(), I, N, PageSize, and T.

size()

template<typename T, size_t PageSize = 1024 / sizeof(T)>


The documentation for this class was generated from the following file: