public static void ExtraDisposesAreIgnored() { OwnedMemory <int> block = MemoryPool <int> .Shared.Rent(42); block.Dispose(); block.Dispose(); }
static void TestLifetime(OwnedMemory <byte> owned) { Memory <byte> copyStoredForLater; try { Memory <byte> memory = owned.Memory; Memory <byte> memorySlice = memory.Slice(10); copyStoredForLater = memorySlice; var r = memorySlice.Retain(); try { Assert.Throws <InvalidOperationException>(() => { // memory is reserved; premature dispose check fires owned.Dispose(); }); } finally { r.Dispose(); // release reservation } } finally { owned.Dispose(); // can finish dispose with no exception } Assert.Throws <ObjectDisposedException>(() => { // memory is disposed; cannot use copy stored for later var span = copyStoredForLater.Span; }); }
public void DisposeStore() { _secretStore?.Dispose(); _secretStore = null; _state.HandshakeHash?.Dispose(); _state.HandshakeHash = null; }
static void BufferLifetimeBasicsAuto(OwnedMemory <byte> buffer) { Memory <byte> copyStoredForLater; try { Memory <byte> memory = buffer.Memory; Memory <byte> slice = memory.Slice(10); copyStoredForLater = slice; var handle = slice.Retain(); try { Assert.Throws <InvalidOperationException>(() => { // memory is reserved; premature dispose check fires buffer.Dispose(); }); } finally { handle.Dispose(); // release reservation } } finally { buffer.Dispose(); // can finish dispose with no exception } Assert.ThrowsAny <ObjectDisposedException>(() => { // memory is disposed; cannot use copy stored for later var span = copyStoredForLater.Span; }); Assert.True(buffer.IsDisposed); }
public void Dispose() { if (_memory == null) { throw new InvalidOperationException("Cannot dispose non-root database"); } _memory.Dispose(); }
public static void IsDisposed() { OwnedMemory <int> block = MemoryPool <int> .Shared.Rent(42); Assert.False(block.IsDisposed); block.Dispose(); Assert.True(block.IsDisposed); block.Dispose(); Assert.True(block.IsDisposed); }
public override void Return(OwnedMemory<byte> buffer) { var ownedArray = buffer as OwnedArray<byte>; if (ownedArray == null) throw new InvalidOperationException("buffer not rented from this pool"); ArrayPool<byte>.Shared.Return(ownedArray.Array); buffer.Dispose(); }
public static void NoPinAfterDispose() { OwnedMemory <int> block = MemoryPool <int> .Shared.Rent(42); block.Dispose(); Assert.Throws <ObjectDisposedException>(() => block.Pin()); }
public override void Return(OwnedMemory <byte> buffer) { var pooledBuffer = buffer as BufferManager; if (pooledBuffer == null) { throw new Exception(); } var memory = pooledBuffer.Pointer.ToInt64(); if (memory < _memory.ToInt64() || memory > _memory.ToInt64() + _bufferSize * _bufferCount) { throw new Exception("not rented from this pool"); } var offset = memory - _memory.ToInt64(); var index = offset / _bufferSize; lock (_lock) { buffer.Dispose(); if (_rented[index] == false) { throw new Exception("this buffer is not rented"); } _rented[index] = false; } }
static void DisposeAuto(OwnedMemory <byte> buffer) { var length = buffer.Length; buffer.Dispose(); Assert.True(buffer.IsDisposed); Assert.ThrowsAny <ObjectDisposedException>(() => { var ignore = buffer.Span; }); Assert.ThrowsAny <ObjectDisposedException>(() => { buffer.Span.Slice(0, length); }); Assert.ThrowsAny <ObjectDisposedException>(() => { buffer.Pin(); }); Assert.ThrowsAny <ObjectDisposedException>(() => { var rwBuffer = buffer.Memory; }); Assert.ThrowsAny <ObjectDisposedException>((Action)(() => { ReadOnlyMemory <byte> roBuffer = buffer.Memory; })); }
public static void NoTryGetArrayAfterDispose() { OwnedMemory <int> block = MemoryPool <int> .Shared.Rent(42); Memory <int> memory = block.Memory; block.Dispose(); Assert.Throws <ObjectDisposedException>(() => MemoryMarshal.TryGetArray(memory, out ArraySegment <int> arraySegment)); }
public void Dispose() { Debug.Assert(_buffer.ReferenceCount >= 1); _buffer.Release(); if (_buffer.ReferenceCount == 0) { _buffer.Dispose(); } }
public void Dispose() { Debug.Assert(_buffer.HasOutstandingReferences); _buffer.Release(); if (!_buffer.HasOutstandingReferences) { _buffer.Dispose(); } }
public void Dispose() { if (_pool == null) { throw new InvalidOperationException("only root object can (and should) be disposed."); } _db = ReadOnlySpan <byte> .Empty; _values = ReadOnlySpan <byte> .Empty; _dbMemory.Dispose(); _dbMemory = null; }
public override void Return(OwnedMemory <byte> buffer) { var ownedArray = buffer as OwnedArray <byte>; if (ownedArray == null) { throw new InvalidOperationException("buffer not rented from this pool"); } ArrayPool <byte> .Shared.Return(ownedArray.Array); buffer.Dispose(); }
private void ResizeDb() { var oldData = _scratchMemory.Span; var newScratch = _pool.Rent(_scratchMemory.Length * 2); int dbLength = newScratch.Length / 2; var newDb = newScratch.Memory.Slice(0, dbLength); _db.Slice(0, _valuesIndex).Span.CopyTo(newDb.Span); _db = newDb; var newStackMemory = newScratch.Memory.Slice(dbLength); _stack.Resize(newStackMemory); _scratchManager.Dispose(); _scratchManager = newScratch; }
protected override void Dispose(bool disposing) { _pool.CheckDisposed(); _ownedMemory.Dispose(); }
public void Dispose() { _keyStore.Dispose(); _ctx.Free(); GC.SuppressFinalize(this); }