Read/Write bytes directly from data array #41
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "Rob-Hague/MatFileHandler:span"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This uses span methods (namely MemoryMarshal.AsBytes) to avoid the creation of an additional byte array for the data when reading/writing. It therefore cuts memory in half (more or less) when reading, and given a premade IMatFile, eliminates (more or less) the memory allocations that result from writing the data arrays.
This change adds a .NET 8 target to get native support for
Span<T>
and relevant APIs. Since older targets do not natively supportSpan<T>
, it adds a nuget reference to Microsoft.Bcl.Memory which allows them to be used. Even though relevant span-taking APIs are not available (such asStream.Read(Span<byte>)
), we can still achieve memory improvements on older targets using extension methods that rent an array from a pool rather than create one.The nuget reference is only available for .NET Framework 4.6.2, since 4.6.1 is EOL (since 2022), so this change also involves bumping that target. Hopefully that is OK. There are other options if net461 should stay
Checkout
From your project repository, check out a new branch and test the changes.