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
TRepresents 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
capacityintThe initial capacity of the queue.
handleAllocationHandleThe allocation handle.
allocationOptionAllocationOptionThe allocation option.
Properties
Capacity
public readonly int Capacity { get; }
Property Value
Count
Gets the number of elements in a collection.
public readonly int Count { get; }
Property Value
IsCreated
Indicates whether the object has been created. Returns true if the object is created, otherwise false.
public readonly bool IsCreated { get; }
Property Value
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
indexint
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
valueTThe item to be added to the collection.
GetEnumerator()
[UnscopedRef]
public UnsafeQueue<T>.Enumerator GetEnumerator()
Returns
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
newSizeintSpecifies the new size to which the collection should be adjusted.
optionAllocationOptionSpecifies 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
valueTThe 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
valueTThe item at the front of the queue if the operation is successful; otherwise, the default value of
T.