I have a sequence of lines:
BinaryReader br;
[...]
//for reading a row from binary file.
MyObj[] retval = new MyObj[count];
br.BaseStream.Seek(
beginSeek +
sizeof(Int16) * offsetX +
(offsetY + count - 1) * dataPerLine * sizeof(Int16),
SeekOrigin.Begin);
for (int x = 0; x < count; x++)
{
retval[x] = new MyObj();
retval[x].prop = br.ReadInt16();
}
//for reading a column from binary file.
MyObj[] retval = new MyObj[count];
for (int y = 0; y < count; y++)
{
br.BaseStream.Seek(
beginSeek +
sizeof(Int16) * (offsetX + count - 1) +
(offsetY + y) * dataPerLine * sizeof(Int16),
SeekOrigin.Begin);
retval[y] = new MyObj();
retval[y].prop = br.ReadInt16();
}
How can I improve this? It finishes run in lots of seconds. Maybe you suggest LINQ, etc.
Seek()
calls. Any way to do it without seeking will undoubtedly be faster. Read everything and keep what you need. – Snowbody Jun 10 at 13:08