public readonly struct NativeArray<T> where T : unmanagedA block of unmanaged memory holding elements, aligned to a chosen boundary and freed by hand. The storage primitive for ECS chunks, vertex staging and layout node arrays.
No guide page documents this yet — the page shows what the code says about itself.
Remarks
Why not a managed array. Nothing here moves, so a pointer into it stays valid without pinning and can be handed to a GPU driver directly. It costs nothing at collection time, however large it is, because the GC never walks it. And the alignment is a promise rather than a hope: a T[] is aligned to the object header's requirements and nothing more, which is not enough for AVX loads or for a mapped buffer's requirements.
It is not garbage collected. Forgetting to dispose one leaks memory the profiler will not attribute to anything. Under a debug build every allocation is registered with LeakTracker, which is how the leak becomes a stack trace instead of a mystery; in release that machinery compiles away and the discipline is the caller's.
Fields and properties (7)
public const int DefaultAlignmentThe default alignment: 64 bytes, one cache line on every architecture Vixen targets. Enough for AVX-512 loads, and it keeps two arrays from sharing a line and forcing the cores writing to them to fight over it.
public static NativeArray<T> EmptyAn array with no memory behind it.
public int LengthHow many elements the array holds.
public long ByteLengthHow many bytes it occupies.
public bool IsEmptyWhether the array holds no memory.
public T* PointerThe address of the first element, for interop and for passing to a driver.
public ref T this[int index]A reference to the element at .
Methods (14)
public NativeArray(int length, int alignment = 64, string? name = null)Allocates elements of uninitialised memory.
public static NativeArray<T> Zeroed(int length, int alignment = 64, string? name = null)Allocates elements and zeroes them.
public static NativeArray<T> From(ReadOnlySpan<T> source, int alignment = 64, string? name = null)Allocates an array holding a copy of .
public Span<T> AsSpan()The elements as a span.
public Span<T> AsSpan(int start, int count)A slice of the elements as a span.
public Span<byte> AsBytes()The raw bytes, for uploads and hashing.
public void Dispose()Frees the memory.
public bool Equals(NativeArray<T> other)Whether two arrays name the same allocation.
public override bool Equals(object? obj)Indicates whether this instance and a specified object are equal.
public override int GetHashCode()Returns the hash code for this instance.
public static bool operator ==(NativeArray<T> left, NativeArray<T> right)Whether two arrays name the same allocation.
public static bool operator !=(NativeArray<T> left, NativeArray<T> right)Whether two arrays name different allocations.
public Span<T>.Enumerator GetEnumerator()Enumerates the elements.
public override string ToString()Returns the fully qualified type name of this instance.
Used by (7)
- CullJobVixen.Rendering
- LayoutTreeVixen.Ui.Layout
- MemoryTestsVixen.Core.Memory.Tests
- ParticleBufferVixen.Vfx
- RenderObjectStoreVixen.Rendering
- TypedArrayVixen.Rendering
- VisibilityGroupVixen.Rendering