public PoolPointer Allocate(long size) { if (size > PoolSize) { return(null); } long currentScanOffset = 0; lock (PoolPointers) { foreach (var pointer in PoolPointers.OrderBy(x => x.Offset).ToArray()) { if (pointer.Offset - currentScanOffset >= size) { var newPointer = new PoolPointer(this, currentScanOffset, size, DefaultFixed); PoolPointers.Add(newPointer); return(newPointer); } currentScanOffset = pointer.Offset + pointer.Length; } if (PoolSize - currentScanOffset >= size) { var newPointer = new PoolPointer(this, currentScanOffset, size, DefaultFixed); PoolPointers.Add(newPointer); return(newPointer); } } return(null); }
protected void UnpinPointer(PoolPointer pointer) { lock (PoolPointers) { PinnedPointers.Remove(pointer); } }
public IMemoryOwner <byte> GetMemory(PoolPointer poolPointer) { lock (PoolPointers) { PinnedPointers.Add(poolPointer); return(new AllocatorMemoryOwner(this, poolPointer, UnderlyingMemory.Slice((int)poolPointer.Offset, (int)poolPointer.Length))); } }
public void Release(PoolPointer poolPointer) { lock (PoolPointers) { if (PinnedPointers.Contains(poolPointer)) { throw new InvalidOperationException("Cannot release a pool pointer that is currently pinned"); } PoolPointers.Remove(poolPointer); } }
public AllocatorMemoryOwner(Allocator allocator, PoolPointer pointer, Memory <byte> memory) { Allocator = allocator; Memory = memory; PoolPointer = pointer; }