/// <summary> /// Check stream reallocation. /// </summary> /// <param name="mem">Memory.</param> private void CheckStreamReallocate(IPlatformMemory mem) { Assert.IsTrue(mem.Capacity >= 256); int dataLen = 2048 + 13; Random rand = new Random(); byte[] data = new byte[dataLen]; for (int i = 0; i < data.Length; i++) { data[i] = (byte)rand.Next(0, 255); } using (var stream = mem.GetStream()) { stream.WriteByteArray(data); stream.SynchronizeOutput(); Assert.IsTrue(mem.Capacity >= dataLen); stream.Reset(); stream.SynchronizeInput(); byte[] data0 = stream.ReadByteArray(dataLen); Assert.AreEqual(data, data0); } }
public PlatformMemoryStream(IPlatformMemory mem) { _mem = mem; _data = (byte*)mem.Data; _cap = mem.Capacity; _len = mem.Length; }
/// <summary> /// Constructor. /// </summary> /// <param name="mem">Memory.</param> public PlatformMemoryStream(IPlatformMemory mem) { _mem = mem; Data = (byte *)mem.Data; _cap = mem.Capacity; _len = mem.Length; }
/// <summary> /// Initializes a new instance of the <see cref="BinarizableReadBenchmark"/> class. /// </summary> public BinarizableReadBenchmark() { _marsh = new Marshaller(new BinaryConfiguration { TypeConfigurations = new List <BinaryTypeConfiguration> { new BinaryTypeConfiguration(typeof(Address)), new BinaryTypeConfiguration(typeof(TestModel)) } }); _mem = _memMgr.Allocate(); var stream = _mem.GetStream(); //_marsh.StartMarshal(stream).Write(_model); _marsh.StartMarshal(stream).Write(_address); stream.SynchronizeOutput(); }
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(); }
/// <summary> /// Initializes a new instance of the <see cref="BinarizableReadBenchmark"/> class. /// </summary> public BinarizableReadBenchmark() { _marsh = new Marshaller(new BinaryConfiguration { TypeConfigurations = new List<BinaryTypeConfiguration> { new BinaryTypeConfiguration(typeof (Address)), new BinaryTypeConfiguration(typeof (TestModel)) } }); _mem = _memMgr.Allocate(); var stream = _mem.GetStream(); //_marsh.StartMarshal(stream).Write(_model); _marsh.StartMarshal(stream).Write(_address); stream.SynchronizeOutput(); }
/// <summary> /// Constructor. /// </summary> /// <param name="mem"></param> public PlatformBigEndianMemoryStream(IPlatformMemory mem) : base(mem) { // No-op. }
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(); } }
/// <summary> /// Check stream reallocation. /// </summary> /// <param name="mem">Memory.</param> private void CheckStreamReallocate(IPlatformMemory mem) { Assert.IsTrue(mem.Capacity >= 256); int dataLen = 2048 + 13; Random rand = new Random(); byte[] data = new byte[dataLen]; for (int i = 0; i < data.Length; i++) data[i] = (byte)rand.Next(0, 255); using (var stream = mem.GetStream()) { stream.WriteByteArray(data); stream.SynchronizeOutput(); Assert.IsTrue(mem.Capacity >= dataLen); stream.Reset(); stream.SynchronizeInput(); byte[] data0 = stream.ReadByteArray(dataLen); Assert.AreEqual(data, data0); } }