NativeArray<T>
Namespace: SharpPluginLoader.Core
A wrapper around a native array.
public struct NativeArray<T>
Type Parameters
T
The type of the underlying elements
Inheritance Object → ValueType → NativeArray<T>
Implements IEnumerable<T>, IEnumerable, IDisposable
Remarks:
Note: If you don't need to use the array in an iterator, use a Span<T> instead.
Properties
Length
The number of elements in the array.
public int Length { get; private set; }
Property Value
Address
The address of the first element in the array.
public nint Address { get; private set; }
Property Value
Pointer
A pointer to the first element in the array.
public T* Pointer { get; }
Property Value
T*
Item
public T& Item { get; }
Property Value
T&
Constructors
NativeArray(IntPtr, Int32, Boolean)
A wrapper around a native array.
NativeArray(nint address, int length, bool ownsPointer)
Parameters
address
IntPtr
The address of the first element
length
Int32
The number of elements in the array
ownsPointer
Boolean
Whether or not the array owns the pointer
Remarks:
Note: If you don't need to use the array in an iterator, use a Span<T> instead.
Methods
Create(Int32)
Creates a new native array from a given address and count.
NativeArray<T> Create(int length)
Parameters
length
Int32
The number of elements
Returns
NativeArray<T>
The newly allocated native array
Remarks:
Warning: The memory allocated by this method is not automatically freed. You must call NativeArray<T>.Dispose() when you are done with the array. Alternatively, use a using statement to ensure that the array is disposed.
Slice(Int32, Int32)
NativeArray<T> Slice(int start, int newLength)
Parameters
start
Int32
newLength
Int32
Returns
AsSpan()
Creates a span over the native array.
Span<T> AsSpan()
Returns
Span<T>
A span over the native array.
Resize(Int32)
Resizes the native array.
void Resize(int newLength)
Parameters
newLength
Int32
The new size
Remarks:
Warning: This method can only be called on NativeArrays that were created using the NativeArray<T>.Create(Int32) method.
GetEnumerator()
IEnumerator<T> GetEnumerator()
Returns
IEnumerator<T>
Dispose()
Disposes the native array.
void Dispose()