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:
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user