Exemple #1
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);
            }
        }
        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);
            }
        }
Exemple #3
0
 public void Clear()
 {
     using (_threadSentinel.TestThreadSafety())
     {
         MemoryUtilities.MemClear <T>(_ptr, _capacity);
     }
 }
Exemple #4
0
        public NativeBag(Allocator allocator)
        {
            unsafe
            {
                var sizeOf   = MemoryUtilities.SizeOf <UnsafeBlob>();
                var listData = (UnsafeBlob *)MemoryUtilities.Alloc((uint)sizeOf, allocator);

                //clear to nullify the pointers
                MemoryUtilities.MemClear((IntPtr)listData, (uint)sizeOf);
                listData->allocator = allocator;
                _queue = listData;
            }
        }
Exemple #5
0
        public NativeBag(Allocator allocator)
        {
            unsafe
            {
                var sizeOf   = MemoryUtilities.SizeOf <UnsafeBlob>();
                var listData = (UnsafeBlob *)MemoryUtilities.Alloc((uint)sizeOf, allocator);

                //clear to nullify the pointers
                MemoryUtilities.MemClear((IntPtr)listData, (uint)sizeOf);
                listData->allocator = allocator;
                _queue = listData;
#if DEBUG && !PROFILE_SVELTO
                _threadSentinel = 0;
#endif
            }
        }
Exemple #6
0
        public ThreadSafeNativeBag(Allocator allocator, uint capacity)
        {
            unsafe
            {
                var sizeOf   = MemoryUtilities.SizeOf <UnsafeBlob>();
                var listData = (UnsafeBlob *)MemoryUtilities.Alloc((uint)sizeOf, allocator);

                //clear to nullify the pointers
                MemoryUtilities.MemClear((IntPtr)listData, (uint)sizeOf);
                listData->allocator = allocator;
                _queue = listData;
                _queue->Realloc(capacity);
            }

            _writingGuard = 0;
        }
        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;
        }
Exemple #8
0
 public void Clear()
 {
     MemoryUtilities.MemClear(_ptr, (uint)(_capacity * MemoryUtilities.SizeOf <T>()));
 }
Exemple #9
0
 public void Clear()
 {
     MemoryUtilities.MemClear <T>(_ptr, _capacity);
 }