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;
        }
Exemplo n.º 2
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;
        }