I want to copy a section of a memory stream into an array of doubles. Something like:
MemoryStream stream = new(File.ReadAllBytes(pathToFileWithBinaryData));
int arrayLength = stream.Length/sizeof(double);
double[] array = new double[arrayLength];
byte[] buffer = new byte[sizeof(double)];
int i=0;
while(stream.Position < stream.Length)
{
stream.Read(buffer, 0, sizeof(double));
array[i] = BitConvert.ToDouble(buffer);
}
But, I don't want to copy the values from buffer
to array
one at a time. The C/C++ programmer in me is inclined to tackle it this way:
byte[] buffer = /* the memory address of the variable 'array' ??? */
stream.Read(buffer, 0, stream.Length);
and then I would have all the values in array
because it is the memory that stream.Read
copied into. Is there a way to do this? Then I could use stream.ReadAsync
and be very happy.