/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> protected virtual void Dispose(bool disposing) { if (disposing) { SynchronizeOutput(); } _mem.Release(); }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> private void Dispose(bool disposing) { if (disposing) { SynchronizeOutput(); } _mem.Release(); }
public void TestUnpooledStreamReallocate() { PlatformMemoryManager mgr = new PlatformMemoryManager(256); for (int i = 0; i < 3; i++) { mgr.Allocate(); } IPlatformMemory mem = mgr.Allocate(); try { Assert.IsTrue(mem is PlatformUnpooledMemory); CheckStreamReallocate(mem); } finally { mem.Release(); } }
public void TestUnpooled() { PlatformMemoryManager mgr = new PlatformMemoryManager(256); for (int i = 0; i < 3; i++) { mgr.Allocate(); } IPlatformMemory mem1 = mgr.Allocate(); Assert.IsTrue(mem1 is PlatformUnpooledMemory); Assert.IsTrue(mem1.Capacity >= 256); Assert.IsTrue(mem1.Pointer > 0); Assert.IsTrue(mem1.Data > 0); Assert.AreEqual(0, mem1.Length); mem1.Reallocate(512); Assert.IsTrue(mem1.Capacity >= 512); Assert.IsTrue(mem1.Pointer > 0); Assert.IsTrue(mem1.Data > 0); Assert.AreEqual(0, mem1.Length); mem1.Length = 128; Assert.AreEqual(128, mem1.Length); mem1.Release(); IPlatformMemory mem2 = mgr.Allocate(); Assert.AreNotSame(mem1, mem2); Assert.IsTrue(mem2.Capacity >= 256); Assert.IsTrue(mem2.Pointer > 0); Assert.IsTrue(mem2.Data > 0); Assert.AreEqual(0, mem2.Length); mem2.Release(); }
/** <inheritdoc /> */ public void Dispose() { SynchronizeOutput(); _mem.Release(); }
public void TestPooled() { PlatformMemoryManager mgr = new PlatformMemoryManager(256); var mem1 = mgr.Allocate(); Assert.IsTrue(mem1 is PlatformPooledMemory); Assert.IsTrue(mem1.Capacity >= 256); Assert.IsTrue(mem1.Pointer > 0); Assert.IsTrue(mem1.Data > 0); Assert.AreEqual(0, mem1.Length); mem1.Reallocate(512); Assert.IsTrue(mem1.Capacity >= 512); Assert.IsTrue(mem1.Pointer > 0); Assert.IsTrue(mem1.Data > 0); Assert.AreEqual(0, mem1.Length); mem1.Length = 128; Assert.AreEqual(128, mem1.Length); mem1.Release(); Assert.AreSame(mem1, mgr.Allocate()); Assert.IsTrue(mem1.Capacity >= 512); Assert.IsTrue(mem1.Pointer > 0); Assert.IsTrue(mem1.Data > 0); Assert.AreEqual(128, mem1.Length); IPlatformMemory mem2 = mgr.Allocate(); Assert.IsTrue(mem2 is PlatformPooledMemory); IPlatformMemory mem3 = mgr.Allocate(); Assert.IsTrue(mem3 is PlatformPooledMemory); mem1.Release(); Assert.AreSame(mem1, mgr.Allocate()); mem2.Release(); Assert.AreSame(mem2, mgr.Allocate()); mem3.Release(); Assert.AreSame(mem3, mgr.Allocate()); mem1.Release(); mem2.Release(); Assert.AreSame(mem1, mgr.Allocate()); Assert.AreSame(mem2, mgr.Allocate()); IPlatformMemory unpooled = mgr.Allocate(); try { Assert.IsTrue(unpooled is PlatformUnpooledMemory); } finally { unpooled.Release(); } }