コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
        public static NativeArray <T> ToNativeArray <T>(this NativeDynamicArray array) where T : struct
        {
            unsafe
            {
                var nativeArray = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <T>(
                    (void *)array.ToIntPTR <T>(), (int)array.Count <T>(), Allocator.None);
#if ENABLE_UNITY_COLLECTIONS_CHECKS
                NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref nativeArray, AtomicSafetyHandle.Create());
#endif
                return(nativeArray);
            }
        }
コード例 #5
0
 public NativeDynamicArrayCast(NativeDynamicArray array) : this()
 {
     _array = array;
 }
コード例 #6
0
 public NativeDynamicArrayCast(uint size, Allocator allocator)
 {
     _array = NativeDynamicArray.Alloc <T>(allocator, size);
 }