public SimpleAllocator(long maxSize, byte maxHeight) : base(maxHeight) { _maxSize = maxSize; _buffer.Add(null); var headNodeSize = SkipListNode.CalculateSizeNeeded(maxHeight, 0); _headNodeLocation = AllocateNode(headNodeSize, out var memory); _ = new SkipListNode(memory, _headNodeLocation, maxHeight, Array.Empty <byte>()); }
public SkipListNode AllocateNode(ReadOnlySpan <byte> key) { var height = _heightGenerator.GetHeight(); var memoryNeeded = SkipListNode.CalculateSizeNeeded(height, key.Length); var nodeLocation = AllocateNode(memoryNeeded, out var memory); if (nodeLocation == 0) { return(new SkipListNode()); } var returnValue = new SkipListNode(memory, nodeLocation, height, key); return(returnValue); }
public NativeAllocator(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 = SkipListNode.CalculateSizeNeeded(maxHeight, 0); AllocateNode(headNodeSize, out var memory); _ = new SkipListNode(memory, ALIGNMENTSIZE, maxHeight, Array.Empty <byte>()); }