I wish to obtain the original value a Span represents. Take the following code for example, how would I, in DoWork
, gain access to the original byte array without creating a copy of it?
static void Main()
{
var data = new byte[0x100];
DoWork(new Span<byte>(data));
}
private void DoWork(Span<byte> Data)
{
//var data = Data.ToArray(); Unsuitable; creates a copy
//var data = (byte[])Data; Unsuitable; doesn't work
//MemoryMarshal. Something in here may work, but unsure
//MemoryExtensions. Something in here may work, but unsure
}
I found 2 static classes with helper methods (shown above) that may help, but I am unsure as to what is the best way to do this without making things slower than just making a copy.