I am trying to stackalloc some memory; and use it as a NativeArray like this:
[StructLayout(LayoutKind.Sequential)]
public struct Vertex : IComparable<Vertex>
{
public readonly static int Size = UnsafeUtility.SizeOf<Vertex>();
public float2 Point;
public float2 Comparend;
public int CompareTo(Vertex other)
{
var diff = Comparend.x - other.Comparend.x;
return diff == 0 ? 0 : diff > 0 ? 1 : -1;
}
}
public void SomeFunction()
{
var n = H.Length;
byte* stackB = stackalloc byte[n * Vertex.Size];
var a= NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray<Vertex>(stackB ,n, Allocator.None);
//pop some data
a.Sort();
}
Is it safe to use it this way? Is the NativeArray okay without safety handle?