I read files into memory and then decode them. At first I created by own class based on TStream and implemented methods to read a Byte, a Cardinal, a Word etc from a stream:
function getWord: Word;
function getCardinal: Cardinal;
function getFloat: Real;
function getNibble: Byte;
It makes it easier to write code that decodes data in files.
But it's painfully slow compared to reading files into an array of Byte an then operating on bytes inline.
I use Delphi 7. There are no inline functions and calling functions is quite slow. So I am thinking how can I make my code easy to understand/write without functions and methods (so it's fast).
My only idea is something like this:
var
Bytes: array[0..40960-1] of Byte;
Words: array[0..20480-1] of Word absolute Bytes;
Cardinals: array[0..10240-1] of Cardinal absolute Bytes;
Is there a way to quickly (and elegantly) read various data types from files?