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:
Matthias Heil
2026-11-19 09:50:21 +01:00
parent b08fbe13ee
commit a42b3393d4
4 changed files with 84 additions and 7 deletions
+15 -5
View File
@@ -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();