public static NativeDynamicArray Alloc <T>(Allocator allocator, uint newLength = 0) where T : struct { unsafe { #if DEBUG && !PROFILE_SVELTO var rtnStruc = new NativeDynamicArray { _hashType = TypeHash <T> .hash }; #else NativeDynamicArray rtnStruc = default; #endif var sizeOf = MemoryUtilities.SizeOf <T>(); uint structSize = (uint)MemoryUtilities.SizeOf <UnsafeArray>(); UnsafeArray *listData = (UnsafeArray *)MemoryUtilities.Alloc(structSize, allocator); //clear to nullify the pointers //MemoryUtilities.MemClear((IntPtr) listData, structSize); rtnStruc._allocator = allocator; listData->Realloc((uint)(newLength * sizeOf), allocator); rtnStruc._list = listData; return(rtnStruc); } }
public static NativeDynamicArray Alloc <T>(Allocator allocator, uint newLength = 0) where T : unmanaged { unsafe { var rtnStruc = new NativeDynamicArray(); #if DEBUG && !PROFILE_SVELTO rtnStruc.hashType = TypeHash <T> .hash; #endif var sizeOf = MemoryUtilities.SizeOf <T>(); uint pointerSize = (uint)MemoryUtilities.SizeOf <UnsafeArray>(); UnsafeArray *listData = (UnsafeArray *)MemoryUtilities.Alloc(pointerSize, allocator); //clear to nullify the pointers MemoryUtilities.MemClear((IntPtr)listData, pointerSize); listData->allocator = allocator; listData->Realloc <T>((uint)(newLength * sizeOf)); rtnStruc._list = listData; return(rtnStruc); } }
public static NativeDynamicArray Alloc <T>(Allocator allocator, uint newLength = 0) where T : struct { unsafe { #if ENABLE_DEBUG_CHECKS var rtnStruc = new NativeDynamicArray { _hashType = TypeHash <T> .hash, }; #else NativeDynamicArray rtnStruc = default; #endif UnsafeArray *listData = (UnsafeArray *)MemoryUtilities.Alloc <UnsafeArray>(1, allocator); //clear to nullify the pointers //MemoryUtilities.MemClear((IntPtr) listData, structSize); rtnStruc._allocator = allocator; listData->Realloc <T>(newLength, allocator); rtnStruc._list = listData; return(rtnStruc); } }
public AtomicNativeBags(Allocator allocator) { _allocator = allocator; _threadsCount = JobsUtility.MaxJobThreadCount + 1; var bufferSize = MemoryUtilities.SizeOf <NativeBag>(); var bufferCount = _threadsCount; var allocationSize = bufferSize * bufferCount; var ptr = (byte *)MemoryUtilities.Alloc((uint)allocationSize, allocator); MemoryUtilities.MemClear((IntPtr)ptr, (uint)allocationSize); for (int i = 0; i < bufferCount; i++) { var bufferPtr = (NativeBag *)(ptr + bufferSize * i); var buffer = new NativeBag(allocator); MemoryUtilities.CopyStructureToPtr(ref buffer, (IntPtr)bufferPtr); } _data = (NativeBag *)ptr; }