Created
December 23, 2021 03:52
-
-
Save neuecc/635982baff01d1d9f5a70cadf7dbf088 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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