Table of Contents

Struct UnsafeQueue<T>

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

A structure that implements a queue using unmanaged types for efficient memory management.

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

Type Parameters

T

Represents the type of elements stored in the queue, which must be an unmanaged type for performance and safety.

Implements
Inherited Members

Constructors

UnsafeQueue()

Initializes a new instance of UnsafeQueue with a default size of 1 and a persistent allocation handle.

public UnsafeQueue()

UnsafeQueue(int, AllocationHandle, AllocationOption)

Initializes a new instance of UnsafeQueue with the specified initial capacity and allocation handle.

public UnsafeQueue(int capacity, AllocationHandle handle, AllocationOption allocationOption = AllocationOption.None)

Parameters

capacity int

The initial capacity of the queue.

handle AllocationHandle

The allocation handle.

allocationOption AllocationOption

The allocation option.

Properties

Capacity

public readonly int Capacity { 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 T this[int index] { get; set; }

Parameters

index int

Property Value

T

Methods

Clear()

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

public void Clear()

Dequeue()

Removes and returns the element at the front of the queue. If the queue is empty, an exception is thrown.

public T Dequeue()

Returns

T

The element that was removed from the front of the queue.

Exceptions

InvalidOperationException

Thrown when attempting to dequeue from an empty queue.

Dispose()

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

public void Dispose()

Enqueue(scoped in T)

Adds an element to the end of a collection, resizing if the current capacity is reached. The new element is stored in a circular buffer.

public void Enqueue(scoped in T value)

Parameters

value T

The item to be added to the collection.

GetEnumerator()

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

Returns

UnsafeQueue<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.

Peek()

Returns a reference to the item at the front of the queue without removing it.

public readonly ref T Peek()

Returns

T

A reference to the item at the front of the queue.

Exceptions

InvalidOperationException

Thrown if the queue is empty.

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.

TryDequeue(out T)

Attempts to remove and return an item from a collection. Returns a boolean indicating success or failure.

public bool TryDequeue(out T value)

Parameters

value T

The output variable that will hold the dequeued item if the operation is successful.

Returns

bool

True if an item was successfully dequeued, otherwise false.

TryPeek(out T)

Attempts to return the object at the top of the collection without removing it.

public readonly bool TryPeek(out T value)

Parameters

value T

The item at the front of the queue if the operation is successful; otherwise, the default value of T.

Returns

bool

true if an object was returned successfully; otherwise, false.