Use `SharedBuffer<int>` across the reader and writer apps, with callback-based buffer access. Add bounds checks to array and span read/write operations.
22 lines
586 B
C#
22 lines
586 B
C#
using DotNext;
|
|
using System.Diagnostics;
|
|
|
|
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");
|
|
consumer.BufferAction((span) =>
|
|
{
|
|
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();
|
|
|