3 ms·
Can you give an example?
by DubiousPusher 9y ago
Can you give an example?
- colejohnson66 9y agoThe Github link has an example: 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
- justinvp 9y agoUnsafe is no longer necessary for such cases. This can now be written as: Span<byte> stackSpan = stackalloc byte[100]; See https://github.com/dotnet/coreclr/pull/14503/files https://github.com/dotnet/coreclr/pull/14503/files as an example.
- DubiousPusher 9y agoThanks, this is what I was wondering.
- ComputerGuru 9y agoYup. Perhaps the github links can be updated to reflect this awesomeness?