public NativeAllocator32(int maxSize, byte maxHeight) { _heightGenerator = new SkipList64.SkipListHeightGenerator64(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 = SkipListNode32.CalculateSizeNeeded(maxHeight, 0); AllocateNode(headNodeSize, out var memory); _ = new SkipListNode32(memory, ALIGNMENTSIZE, maxHeight, Array.Empty <byte>()); }
public ArrayBasedAllocator32(int maxSize, byte maxHeight) { _heightGenerator = new SkipList64.SkipListHeightGenerator64(maxHeight); _maxSize = maxSize; _data = new byte[maxSize + ALIGNMENTSIZE - 1]; _gcHandle = GCHandle.Alloc(_data, GCHandleType.Pinned); _initalOffset = (int)(AlignLength(_gcHandle.AddrOfPinnedObject().ToInt64()) - _gcHandle.AddrOfPinnedObject().ToInt64()); if (_initalOffset == 0) { _initalOffset += ALIGNMENTSIZE; } _currentPointer = _initalOffset; var headNodeSize = SkipListNode32.CalculateSizeNeeded(maxHeight, 0); AllocateNode(headNodeSize, out var memory); _ = new SkipListNode32(memory, ALIGNMENTSIZE, maxHeight, Array.Empty <byte>()); }