public void WriteAndReadFromBuffer2() { using (UnmanagedCircularBuffer ncb = UnmanagedCircularBuffer.Create(memoryStart, memoryLength)) { using (Stream ws = ncb.CreateWritingStream()) { ws.WriteByte(0x42); } using (UnmanagedCircularBuffer ncb2 = UnmanagedCircularBuffer.Open(memoryStart)) { using (Stream rs = ncb2.CreateReadingStream()) { Assert.AreEqual(0x42, rs.ReadByte()); } } } }
public void WriteAndReadFromBufferUsingMemoryMappedFile() { using (MemoryMappedFile mmf1 = MemoryMappedFile.CreateSharedMemory("Local\\TestMemory", 1024)) { using (UnmanagedMemory view1 = mmf1.MapView(0, 1024)) { using (UnmanagedCircularBuffer ncb = UnmanagedCircularBuffer.Create(view1.Start, (int)view1.Length)) { using (Stream ws = ncb.CreateWritingStream()) { ws.WriteByte(0x42); } using (MemoryMappedFile mmf2 = MemoryMappedFile.Open("Local\\TestMemory")) { using (UnmanagedMemory view2 = mmf1.MapView(0, 1024)) { Assert.AreNotEqual(view1.Start, view2.Start); using (UnmanagedCircularBuffer ncb2 = UnmanagedCircularBuffer.Open(view2.Start)) { using (Stream rs = ncb2.CreateReadingStream()) { Assert.AreEqual(0x42, rs.ReadByte()); } } } } } } } }