Add checked shared-buffer span operations

Use `SharedBuffer<int>` across the reader and writer apps, with callback-based buffer access. Add bounds checks to array and span read/write operations.
This commit is contained in:
Matthias Heil
2026-11-19 10:16:51 +01:00
parent a42b3393d4
commit 2ce631940d
4 changed files with 60 additions and 24 deletions
+7 -4
View File
@@ -7,12 +7,15 @@ using var producer = new WriterApp.SharedBuffer<int>("MySharedBuffer", length: 1
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++)
consumer.BufferAction((span) =>
{
Debug.Assert(intSpan[i] == intArray[i]);
for (var i = 0; i < span.Length; i++)
{
Debug.Assert(span[i] == intArray[i]);
}
});
}
Console.WriteLine("Start the second program, then press Enter here to close the array");
Console.ReadLine();