public void Resize(uint newCapacity, bool copyContent = true)
        {
            var pointer = _realBuffer.ToNativeArray(out _);

            pointer = MemoryUtilities.Realloc <T>(pointer, newCapacity, _nativeAllocator, (uint)capacity, copyContent);
            NB <T> b = new NB <T>(pointer, newCapacity);

            _realBuffer    = b;
            _invalidHandle = true;
        }
 public void Resize(uint newSize, bool copyContent = true)
 {
     if (newSize != capacity)
     {
         IntPtr pointer = _realBuffer.ToNativeArray(out _);
         pointer = MemoryUtilities.Realloc <T>(pointer, newSize, _nativeAllocator,
                                               newSize > capacity ? (uint)capacity : newSize, copyContent);
         SentinelNB <T> b = new SentinelNB <T>(pointer, newSize);
         _realBuffer    = b;
         _invalidHandle = true;
     }
 }
        public void Resize(uint newCapacity)
        {
            Check.Require(newCapacity > 0, "Resize requires a size greater than 0");
            Check.Require(newCapacity > capacity, "can't resize to a smaller size");

            var pointer = _realBuffer.ToNativeArray(out _);
            var sizeOf  = MemoryUtilities.SizeOf <T>();

            pointer = MemoryUtilities.Realloc(pointer, (uint)(capacity * sizeOf), (uint)(newCapacity * sizeOf)
                                              , Allocator.Persistent);
            NB <T> b = new NB <T>(pointer, newCapacity);

            _buffer     = IntPtr.Zero;
            _realBuffer = b;
        }
        public void AllocateMore(uint newSize, uint numberOfItemsToCopy, bool clear = true)
        {
#if DEBUG && !PROFILE_SVELTO
            if (newSize <= capacity)
            {
                throw new DBC.Common.PreconditionException("can't alloc more to a smaller or equal size");
            }
            if (numberOfItemsToCopy > capacity)
            {
                throw new DBC.Common.PreconditionException("out of bounds number of elements to copy");
            }
#endif
            var pointer = _realBuffer.ToNativeArray(out _);
            pointer = MemoryUtilities.Realloc <T>(pointer, newSize, _nativeAllocator, numberOfItemsToCopy, true, clear);
            NB <T> b = new NB <T>(pointer, newSize);
            _realBuffer    = b;
            _invalidHandle = true;
        }
Exemple #5
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 void Resize(uint newCapacity, bool copyContent = true)
        {
#if DEBUG && !PROFILE_SVELTO
            if (!(newCapacity > 0))
            {
                throw new PreconditionException("Resize requires a size greater or equal to 0");
            }
            if (!(newCapacity > capacity))
            {
                throw new PreconditionException("can't resize to a smaller size");
            }
#endif
            var pointer = _realBuffer.ToNativeArray(out _);
            var sizeOf  = MemoryUtilities.SizeOf <T>();
            pointer = MemoryUtilities.Realloc(pointer, (uint)(capacity * sizeOf), (uint)(newCapacity * sizeOf)
                                              , _nativeAllocator, copyContent);
            NB <T> b = new NB <T>(pointer, newCapacity);
            _realBuffer    = b;
            _invalidHandle = true;
        }
Exemple #7
0
        public void Resize(uint newCapacity)
        {
#if DEBUG && !PROFILE_SVELTO
            if (!(newCapacity > 0))
            {
                throw new PreconditionException("Resize requires a size greater than 0");
            }
            if (!(newCapacity > capacity))
            {
                throw new PreconditionException("can't resize to a smaller size");
            }
#endif
            var pointer = _realBuffer.ToNativeArray(out _);
            var sizeOf  = MemoryUtilities.SizeOf <T>();
            pointer = MemoryUtilities.Realloc(pointer, (uint)(capacity * sizeOf), (uint)(newCapacity * sizeOf)
                                              , Allocator.Persistent);
            NB <T> b = new NB <T>(pointer, newCapacity);
            _buffer     = IntPtr.Zero;
            _realBuffer = b;
        }