class TChunkedArray

template<typename Type, u64 PageSize = 1024>

A dynamically-growing array that stores elements in fixed-size pages (chunks) rather than a single contiguous buffer.

Growth only allocates a new page — existing data is never copied or moved. This makes it ideal for large arrays that grow incrementally.

Template parameters

Type

Element type.

PageSize

Number of elements per page. Must be a power of two.

Public

Constructors

TChunkedArray<Type, PageSize>

TChunkedArray<Type, PageSize>() = default

TChunkedArray<Type, PageSize>

TChunkedArray<Type, PageSize>(const TChunkedArray<Type, PageSize> &other)

TChunkedArray<Type, PageSize>

TChunkedArray<Type, PageSize>(TChunkedArray<Type, PageSize> &&other) noexcept

TChunkedArray<Type, PageSize>

TChunkedArray<Type, PageSize>(u64 size, const Type &value = Type())

TChunkedArray<Type, PageSize>

TChunkedArray<Type, PageSize>(std::initializer_list<Type> list)

Methods

~TChunkedArray<Type, PageSize>

~TChunkedArray<Type, PageSize>()

Begin

Iterator Begin()

End

Iterator End()

Begin

ConstIterator Begin() const

End

ConstIterator End() const

RBegin

ReverseIterator RBegin()

REnd

ReverseIterator REnd()

RBegin

ConstReverseIterator RBegin() const

REnd

ConstReverseIterator REnd() const

Add

void Add(const Type &value)

Appends an element by copy.

Add

void Add(Type &&value)

Appends an element by move.

Pop

void Pop()

Removes and destructs the last element.

Size

u64 Size() const

Returns the number of elements.

Empty

bool Empty() const

Returns true if the array is empty.

Capacity

u64 Capacity() const

Returns the current capacity (number of allocated element slots).

Resize

void Resize(u64 newSize)

Resizes the array.

New elements are value-initialized. If the new size is smaller, trailing elements are destructed. Pages are not freed (use Shrink() for that).

Resize

void Resize(u64 newSize, const Type &value)

Resizes the array, initializing new elements with .

Reserve

void Reserve(u64 capacity)

Pre-allocates pages to hold at least elements.

Does not change size.

Shrink

void Shrink()

Frees any unused trailing pages beyond what is needed for the current size.

Clear

void Clear()

Destructs all elements and frees all pages.

push_back

void push_back(const Type &value)

push_back

void push_back(Type &&value)

pop_back

void pop_back()

size

u64 size() const

empty

bool empty() const

resize

void resize(u64 newSize)

resize

void resize(u64 newSize, const Type &value)

reserve

void reserve(u64 capacity)

begin

iterator begin()

end

iterator end()

begin

const_iterator begin() const

end

const_iterator end() const

rbegin

reverse_iterator rbegin()

rend

reverse_iterator rend()

rbegin

const_reverse_iterator rbegin() const

rend

const_reverse_iterator rend() const

Operators

operator=

TChunkedArray<Type, PageSize> &operator=(const TChunkedArray<Type, PageSize> &other)

operator=

TChunkedArray<Type, PageSize> &operator=(TChunkedArray<Type, PageSize> &&other) noexcept

operator[]

Type &operator[](u64 index)

Returns a reference to the element at the given index.

No bounds checking.

operator[]

const Type &operator[](u64 index) const

Returns a const reference to the element at the given index.

No bounds checking.

Private

Methods

GetElement

Type &GetElement(u64 index)

Returns a reference to the element at index (raw, no construction/destruction).

GetElement

const Type &GetElement(u64 index) const

EnsureCapacity

void EnsureCapacity(u64 requiredSize)

Ensures enough pages are allocated to hold at least elements.

FreeAllPages

void FreeAllPages()

Frees all page allocations and clears the page array.

Does not destruct elements.

DestructRange

void DestructRange(u64 startIndex, u64 endIndex)

Destructs elements in the range [startIndex, endIndex) using per-page iteration.

CopyConstructRange

void CopyConstructRange(const TChunkedArray<Type, PageSize> &other, u64 startIndex, u64 endIndex)

Copy-constructs elements from in the range [startIndex, endIndex) into uninitialized memory.

CopyAssignRange

void CopyAssignRange(const TChunkedArray<Type, PageSize> &other, u64 startIndex, u64 endIndex)

Copy-assigns elements from in the range [startIndex, endIndex) over already-constructed elements.

DefaultConstructRange

void DefaultConstructRange(u64 startIndex, u64 endIndex)

Value-initializes (default-constructs) elements in the range [startIndex, endIndex) in uninitialized memory.

FillConstructRange

void FillConstructRange(u64 startIndex, u64 endIndex, const Type &value)

Copy-constructs elements in the range [startIndex, endIndex) from in uninitialized memory.

Fields

mPages

TArray<Type *> mPages

mSize

u64 mSize