Пример #1
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);
            }
        }
Пример #2
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);
            }
        }
Пример #3
0
 public SharedNativeInt(Allocator allocator)
 {
     unsafe {
         _allocator = allocator;
         data       = (int *)MemoryUtilities.Alloc(sizeof(int), allocator);
     }
 }
Пример #4
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 void Alloc(uint newCapacity)
        {
            DBC.Common.Check.Require(buffer == null || buffer.ToNativeArray(out _) == IntPtr.Zero, "can't alloc an already allocated buffer");

            var    realBuffer = MemoryUtilities.Alloc((uint)(newCapacity * MemoryUtilities.SizeOf <T>()), Allocator.Persistent);
            NB <T> b          = new NB <T>(realBuffer, newCapacity);

            buffer          = b;
            this.realBuffer = b;
        }
Пример #6
0
        public NativeBag(Allocator allocator) : this()
        {
            unsafe
            {
                var listData = (UnsafeBlob *)MemoryUtilities.Alloc <UnsafeBlob>((uint)1, allocator);

                listData->allocator = allocator;
                _queue = listData;
            }
        }
        public SharedSveltoDictionaryNative(uint size)
        {
            var dictionary =
                new SveltoDictionary <TKey, TValue, NativeStrategy <SveltoDictionaryNode <TKey> >, NativeStrategy <TValue>,
                                      NativeStrategy <int> >(size, Allocator.Persistent);

            _sharedDictionary = MemoryUtilities.Alloc <SveltoDictionary <TKey, TValue, NativeStrategy <SveltoDictionaryNode <TKey> >, NativeStrategy <TValue>,
                                                                         NativeStrategy <int> > >(1, Allocator.Persistent);

            _dictionary = dictionary;
        }
Пример #8
0
        public static SharedNativeInt Create(int t, Allocator allocator)
        {
            unsafe {
                var current = new SharedNativeInt();
                current._allocator = allocator;
                current.data       = (int *)MemoryUtilities.Alloc(sizeof(int), allocator);
                *current.data = t;

                return(current);
            }
        }
Пример #9
0
        public SharedSveltoDictionaryNative(uint size, Allocator nativeAllocator)
        {
            var dictionary =
                new SveltoDictionary <TKey, TValue, NativeStrategy <FasterDictionaryNode <TKey> >, NativeStrategy <TValue>,
                                      NativeStrategy <int> >(
                    size, nativeAllocator);
            int structSize = Marshal.SizeOf(dictionary);

            _sharedDictionary = MemoryUtilities.Alloc((uint)structSize, Allocator.Persistent);

            _dictionary = dictionary;
        }
Пример #10
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;
            }
        }
        public void Alloc(uint newCapacity, Allocator nativeAllocator)
        {
            _nativeAllocator = nativeAllocator;

            Check.Require(this._realBuffer.ToNativeArray(out _) == IntPtr.Zero
                          , "can't alloc an already allocated buffer");

            var realBuffer =
                MemoryUtilities.Alloc((uint)(newCapacity * MemoryUtilities.SizeOf <T>()), _nativeAllocator);
            NB <T> b = new NB <T>(realBuffer, newCapacity);

            _buffer          = IntPtr.Zero;
            this._realBuffer = b;
        }
Пример #12
0
        public void Alloc(uint newCapacity, Allocator allocator, bool clear = true)
        {
#if DEBUG && !PROFILE_SVELTO
            if (!(this._realBuffer.ToNativeArray(out _) == IntPtr.Zero))
            {
                throw new DBC.Common.PreconditionException("can't alloc an already allocated buffer");
            }
#endif
            _nativeAllocator = allocator;

            var    realBuffer = MemoryUtilities.Alloc <T>(newCapacity, _nativeAllocator, clear);
            NB <T> b          = new NB <T>(realBuffer, newCapacity);
            _buffer     = default;
            _realBuffer = b;
        }
Пример #13
0
        public NativeBag(Allocator allocator)
        {
            unsafe
            {
                var listData = (UnsafeBlob *)MemoryUtilities.Alloc <UnsafeBlob>((uint)1, allocator);

                //clear to nullify the pointers
                //MemoryUtilities.MemClear((IntPtr) listData, (uint) sizeOf);
                listData->allocator = allocator;
                _queue = listData;
#if ENABLE_THREAD_SAFE_CHECKS
                _threadSentinel = 0;
#endif
            }
        }
Пример #14
0
        public void Alloc(uint newCapacity, Allocator nativeAllocator)
        {
#if DEBUG && !PROFILE_SVELTO
            if (!(this._realBuffer.ToNativeArray(out _) == IntPtr.Zero))
            {
                throw new PreconditionException("can't alloc an already allocated buffer");
            }
#endif
            _nativeAllocator = nativeAllocator;

            var realBuffer =
                MemoryUtilities.Alloc((uint)(newCapacity * MemoryUtilities.SizeOf <T>()), _nativeAllocator);
            NB <T> b = new NB <T>(realBuffer, newCapacity);
            _buffer     = default;
            _realBuffer = b;
        }
Пример #15
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
            }
        }
Пример #16
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 = = tData;
                _queue->Realloc(capacity);
            }

            _writingGuard = 0;
        }
Пример #17
0
        internal Consumer(string name, uint capacity) : this()
        {
            unsafe {
#if DEBUG && !PROFILE_SVELTO
                _name = name;
#endif
                _ringBuffer = new RingBuffer <ValueTuple <T, EGID> >((int)capacity,
#if DEBUG && !PROFILE_SVELTO
                                                                     _name
#else
                                                                     string.Empty
#endif
                                                                     );
                mustBeDisposed          = MemoryUtilities.Alloc(sizeof(bool), Allocator.Persistent);
                *(bool *)mustBeDisposed = false;
            }
        }
        public static IntPtr Create()
        {
            unsafe
            {
                //allocate the pointer to the dictionary
                IntPtr dic = MemoryUtilities
                             .Alloc <SveltoDictionary <long, Sentinel, SentinelNativeStrategy <SveltoDictionaryNode <long> >,
                                                       SentinelNativeStrategy <Sentinel>, SentinelNativeStrategy <int> > >(1, Allocator.Persistent);

                //allocate the dictionary itself
                Unsafe.AsRef <SveltoDictionary <long, Sentinel, SentinelNativeStrategy <SveltoDictionaryNode <long> >,
                                                SentinelNativeStrategy <Sentinel>, SentinelNativeStrategy <int> > >((void *)dic) =
                    new SveltoDictionary <long, Sentinel, SentinelNativeStrategy <SveltoDictionaryNode <long> >,
                                          SentinelNativeStrategy <Sentinel>, SentinelNativeStrategy <int> >(1, Allocator.Persistent);

                return(dic);
            }
        }
Пример #19
0
        public void Alloc(uint newCapacity, Allocator allocator, bool clear)
        {
#if DEBUG && !PROFILE_SVELTO
            if (!(this._realBuffer.ToNativeArray(out _) == IntPtr.Zero))
            {
                throw new DBC.Common.PreconditionException("can't alloc an already allocated buffer");
            }
            if (allocator != Allocator.Persistent && allocator != Allocator.Temp && allocator != Allocator.TempJob)
            {
                throw new Exception("invalid allocator used for native strategy");
            }
#endif
            _nativeAllocator = allocator;

            IntPtr realBuffer = MemoryUtilities.Alloc <T>(newCapacity, _nativeAllocator, clear);
            NB <T> b          = new NB <T>(realBuffer, newCapacity);
            _invalidHandle = true;
            _realBuffer    = b;
        }
Пример #20
0
 public void TestResize()
 {
     unsafe
     {
         var ptr = MemoryUtilities.Alloc(10, Allocator.Persistent);
         Unsafe.Write((void *)ptr, new Test()
         {
             a   = 3
             , b = 1
         });
         Unsafe.Write((void *)(ptr + 8), (short)-10);
         ptr = MemoryUtilities.Realloc(ptr, 10, Allocator.Persistent, 16);
         var test = Unsafe.Read <Test>((void *)ptr);
         Assert.That(test.a == 3);
         Assert.That(test.b == 1);
         Assert.That(Unsafe.Read <short>((void *)(ptr + 8)) == -10);
         MemoryUtilities.Free(ptr, Allocator.Persistent);
     }
 }
        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;
        }