Skip to content

Instantly share code, notes, and snippets.

@neuecc
Created December 23, 2021 03:52
Show Gist options
  • Save neuecc/635982baff01d1d9f5a70cadf7dbf088 to your computer and use it in GitHub Desktop.
Save neuecc/635982baff01d1d9f5a70cadf7dbf088 to your computer and use it in GitHub Desktop.
// for example, load large file.
using var handle = File.OpenHandle("4GBfile.bin", FileMode.Open, FileAccess.Read, options: FileOptions.Asynchronous);
var size = RandomAccess.GetLength(handle);
// via .NET 6 Scatter/Gather API
using var array = new NativeMemoryArray<byte>(size);
await RandomAccess.ReadAsync(handle, array.AsMemoryList(), 0);
// iterate Span<byte> as chunk
foreach (var chunk in array)
{
Console.WriteLine(chunk.Length);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment