Add typed shared-memory buffer example
Introduce a generic shared buffer with typed span access and timeout-based read/write waits. Update the sample to verify data shared between two buffer views.
This commit is contained in:
+15
-5
@@ -1,8 +1,18 @@
|
||||
using SharedMemory;
|
||||
using DotNext;
|
||||
using System.Diagnostics;
|
||||
|
||||
using var numbers = new SharedArray<int>("MySharedArray", length: 10);
|
||||
numbers[0] = 123;
|
||||
numbers[^1] = 456;
|
||||
Console.WriteLine("WriterApp.SharedBuffer:");
|
||||
using var producer = new WriterApp.SharedBuffer<int>("MySharedBuffer", length: 10);
|
||||
|
||||
var intArray = new int[10] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
|
||||
producer.Write(intArray);
|
||||
using var consumer = new WriterApp.SharedBuffer<int>("MySharedBuffer");
|
||||
var intSpan = consumer.DataSpan;
|
||||
for (var i = 0; i < intSpan.Length; i++)
|
||||
{
|
||||
Debug.Assert(intSpan[i] == intArray[i]);
|
||||
|
||||
}
|
||||
Console.WriteLine("Start the second program, then press Enter here to close the array");
|
||||
Console.ReadLine();
|
||||
Console.ReadLine();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user