OK so I have converted a file into a binary format using BinaryWriter. The format is:
number of ints, followed by the ints.
So the code will be something like:
readLineOfNumbers() {
count = read();
int[] a = read(count ints);
return a;
}
Do I use a BinaryReader? The closest thing I can see there is to read everything into a byte[], but then how do I make that an int array? This all has to be done very efficiently as well. I need buffering and so on.
I don’t know of anything within
BinaryReaderwhich will read an array of integers, I’m afraid. If you read into a byte array you could then useBuffer.BlockCopyto copy those bytes into anint[], which is probably the fastest form of conversion – although it relies on the endianness of your processor being appropriate for your data.Have you tried just looping round, calling
BinaryReader.ReadInt32()as many times as you need to, and letting the file system do the buffering? You could always add aBufferedStreamwith a large buffer into the mix if you thought that would help.