Table of Contents

Struct UnsafeChunkedList<T>

Namespace
Misaki.HighPerformance.LowLevel.Collections
Assembly
Misaki.HighPerformance.LowLevel.dll

A collection that stores elements in fixed-size chunks, enabling stable element addresses and eliminating large reallocation during growth. Adding elements never moves existing ones.

public struct UnsafeChunkedList<T> : IUnsafeCollection<T>, IUnsafeCollection, IDisposable where T : unmanaged

Type Parameters

T

Represents a type that can be stored in the collection, constrained to unmanaged types for performance and safety.

Implements
Inherited Members

Constructors

UnsafeChunkedList()

public UnsafeChunkedList()

UnsafeChunkedList(int, AllocationHandle, AllocationOption)

Initializes a new instance with a specified chunk capacity and allocator.

public UnsafeChunkedList(int chunkCapacity, AllocationHandle handle, AllocationOption allocationOption = AllocationOption.None)

Parameters

chunkCapacity int

The maximum number of elements per chunk.

handle AllocationHandle

A reference to an AllocationHandle that manages memory allocation.

allocationOption AllocationOption

Specifies how the memory should be allocated.

Fields

DEFAULT_CHUNK_SIZE_IN_BYTES

public const int DEFAULT_CHUNK_SIZE_IN_BYTES = 16384

Field Value

int

Properties

Capacity

public readonly int Capacity { get; }

Property Value

int

ChunkCapacity

public readonly int ChunkCapacity { get; }

Property Value

int

ChunkCount

public readonly int ChunkCount { get; }

Property Value

int

Count

Gets the number of elements in a collection.

public readonly int Count { get; }

Property Value

int

IsCreated

Indicates whether the object has been created. Returns true if the object is created, otherwise false.

public readonly bool IsCreated { get; }

Property Value

bool

Remarks

If MHP_ENABLE_STACKTRACE is not defined, this property will only check if the underlying pointer is not null, which may not be sufficient to determine if the collection is fully initialized and ready for use.

this[int]

public readonly ref T this[int index] { get; }

Parameters

index int

Property Value

T

this[uint]

public readonly ref T this[uint index] { get; }

Parameters

index uint

Property Value

T

Methods

Add(scoped in T)

Adds a new element to the end of the list, allocating new chunks as needed.

public void Add(scoped in T value)

Parameters

value T

AddNoResize(scoped in T)

Adds the specified value to the collection. For chunked lists, this is equivalent to Add(scoped in T), since allocating new chunks never moves existing elements.

public void AddNoResize(scoped in T value)

Parameters

value T

AddRange(ReadOnlySpan<T>)

Adds a range of elements to the collection, allocating new chunks as needed.

public void AddRange(ReadOnlySpan<T> values)

Parameters

values ReadOnlySpan<T>

AddRange(T*, int)

Adds a range of elements from a pointer to the collection, allocating new chunks as needed.

public void AddRange(T* ptr, int count)

Parameters

ptr T*
count int

AddRangeNoResize(ReadOnlySpan<T>)

Adds a range of elements. For chunked lists, this is equivalent to AddRange(ReadOnlySpan<T>), since allocating new chunks never moves existing elements.

public void AddRangeNoResize(ReadOnlySpan<T> collection)

Parameters

collection ReadOnlySpan<T>

AddRangeNoResize(T*, int)

Adds a range of elements from a pointer. For chunked lists, this is equivalent to AddRange(T*, int), since allocating new chunks never moves existing elements.

public void AddRangeNoResize(T* ptr, int count)

Parameters

ptr T*
count int

AsParallelReader()

Provides a parallel reader for the current list, enabling thread-safe read operations.

public UnsafeChunkedList<T>.ParallelReader AsParallelReader()

Returns

UnsafeChunkedList<T>.ParallelReader

AsParallelWriter()

Provides a parallel writer for the current list, enabling thread-safe additions.

public UnsafeChunkedList<T>.ParallelWriter AsParallelWriter()

Returns

UnsafeChunkedList<T>.ParallelWriter

Clear()

Removes all elements from the collection. The collection will be empty after this operation.

public void Clear()

CopyFrom(ReadOnlySpan<T>)

Copies elements from a source span into the list, growing as needed.

public void CopyFrom(ReadOnlySpan<T> source)

Parameters

source ReadOnlySpan<T>

CopyFrom(ReadOnlySpan<T>, int, int, int)

Copies a range of elements from a source span to the list.

public void CopyFrom(ReadOnlySpan<T> source, int sourceIndex, int destinationIndex, int length)

Parameters

source ReadOnlySpan<T>
sourceIndex int
destinationIndex int
length int

CopyTo(Span<T>)

Copies all elements into a destination span.

public readonly void CopyTo(Span<T> destination)

Parameters

destination Span<T>

CopyTo(Span<T>, int, int, int)

Copies a range of elements from the list to a destination span.

public readonly void CopyTo(Span<T> destination, int sourceIndex, int destinationIndex, int length)

Parameters

destination Span<T>
sourceIndex int
destinationIndex int
length int

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

EnsureCapacity(int)

Pre-allocates chunks to accommodate at least the specified number of elements.

public void EnsureCapacity(int capacity)

Parameters

capacity int

GetEnumerator()

[UnscopedRef]
public UnsafeChunkedList<T>.Enumerator GetEnumerator()

Returns

UnsafeChunkedList<T>.Enumerator

GetUnsafePtr()

Returns a pointer to an unmanaged memory location. This pointer can be used for low-level memory operations.

public readonly void* GetUnsafePtr()

Returns

void*

The method returns a void pointer to the unsafe memory location.

RemoveAt(int)

Removes the element at the specified index.

public void RemoveAt(int index)

Parameters

index int

RemoveAtSwapBack(int)

Removes the element at the specified index by swapping it with the last element.

public void RemoveAtSwapBack(int index)

Parameters

index int

RemoveRange(int, int)

Removes a range of elements from the list starting at the specified index.

public void RemoveRange(int start, int length)

Parameters

start int
length int

RemoveRangeSwapBack(int, int)

Removes a range of elements by swapping them with elements from the end of the list.

public void RemoveRangeSwapBack(int start, int length)

Parameters

start int
length int

Resize(int, AllocationOption)

Changes the size of a collection to the specified value.

public void Resize(int newSize, AllocationOption option = AllocationOption.None)

Parameters

newSize int

Specifies the new size to which the collection should be adjusted.

option AllocationOption

Specifies allocation options that may affect how memory is managed during the resize operation.

ToList()

Creates a new List<T> containing the elements.

public readonly List<T> ToList()

Returns

List<T>