by ComputerGuru · 9y ago · 0 comments
Span<byte> stackSpan;
unsafe {
byte* stackMemory = stackalloc byte[100];
stackSpan = new Span<byte>(stackMemory, 100);
}
SafeSum(stackSpan);
You still need unsafe to allocate, but once allocated, you can access the memory in a type safe way. M Span<byte> stackSpan = stackalloc byte[100];
See https://github.com/dotnet/coreclr/pull/14503/files as an example.