public AiNativeArray(int length) { if (length <= 0) { throw new ArgumentException("Length must be > 0"); } m_Data = UnsafeArrayData.Create(UnsafeCollectionUtility.SizeOf <T>(), length); }
public static UnsafeArrayData *Create(int sizeOf, int length) { UnsafeArrayData *arrayData = (UnsafeArrayData *)Marshal.AllocHGlobal(UnsafeCollectionUtility.SizeOf <UnsafeArrayData>()); var bytesToMalloc = sizeOf * length; arrayData->Ptr = (void *)Marshal.AllocHGlobal(bytesToMalloc); arrayData->Length = length; return(arrayData); }
public static void Destroy(UnsafeArrayData *listData) { #if DEBUG || ENABLE_UNITY_COLLECTIONS_CHECKS if (listData == null) { throw new InvalidOperationException("UnsafeListData has yet to be created or has been destroyed!"); } #endif listData->Dispose(); Marshal.FreeHGlobal((IntPtr)listData); listData = null; }
public void Dispose() { UnsafeArrayData.Destroy(m_Data); m_Data = null; }