Ejemplo n.º 1
0
        public SimpleAllocator64(long maxSize, byte maxHeight)
            : base(maxHeight)
        {
            _maxSize = maxSize;
            _buffer.Add(Array.Empty <byte>());

            var headNodeSize = SkipListNode64.CalculateSizeNeeded(maxHeight, 0);

            _headNodeLocation = AllocateNode(headNodeSize, out var memory);
            _ = new SkipListNode64(memory, _headNodeLocation, maxHeight, Array.Empty <byte>());
        }
Ejemplo n.º 2
0
        public SkipListNode64 AllocateNode(ReadOnlySpan <byte> key)
        {
            var height       = HeightGenerator.GetHeight();
            var memoryNeeded = SkipListNode64.CalculateSizeNeeded(height, key.Length);
            var nodeLocation = AllocateNode(memoryNeeded, out var memory);

            if (nodeLocation == 0)
            {
                return(new SkipListNode64());
            }

            var returnValue = new SkipListNode64(memory, nodeLocation, height, key);

            return(returnValue);
        }
Ejemplo n.º 3
0
        public NativeAllocator64(long maxSize, byte maxHeight)
            : base(maxHeight)
        {
            _maxSize = maxSize;
            _pointer = VirtualAlloc(IntPtr.Zero, (UIntPtr)maxSize, AllocationType.MEM_COMMIT | AllocationType.MEM_RESERVE, Protection.PAGE_READWRITE);
            if (_pointer == IntPtr.Zero)
            {
                var error = Marshal.GetLastWin32Error();
                throw new OutOfMemoryException($"We could not allocate memory for the skip list error code was {error}");
            }

            _currentPointer = ALIGNMENTSIZE;

            var headNodeSize = SkipListNode64.CalculateSizeNeeded(maxHeight, 0);

            AllocateNode(headNodeSize, out var memory);
            _ = new SkipListNode64(memory, ALIGNMENTSIZE, maxHeight, Array.Empty <byte>());
        }
Ejemplo n.º 4
0
        public ArrayBasedAllocator64(long maxSize, byte maxHeight)
            : base(maxHeight)
        {
            _maxSize      = maxSize;
            _data         = new byte[maxSize + ALIGNMENTSIZE - 1];
            _gcHandle     = GCHandle.Alloc(_data, GCHandleType.Pinned);
            _initalOffset = AlignLength(_gcHandle.AddrOfPinnedObject().ToInt64()) - _gcHandle.AddrOfPinnedObject().ToInt64();
            if (_initalOffset == 0)
            {
                _initalOffset += ALIGNMENTSIZE;
            }
            _currentPointer = _initalOffset;

            var headNodeSize = SkipListNode64.CalculateSizeNeeded(maxHeight, 0);

            AllocateNode(headNodeSize, out var memory);
            _ = new SkipListNode64(memory, ALIGNMENTSIZE, maxHeight, Array.Empty <byte>());
        }