Re: Reading a binary file

new topic     » goto parent     » topic index » view thread      » older message » newer message

Hy,

I actually do not see what's the problem with speed in
retreiving data from files, I always use this:

integer hnd,char
sequence filestr
filestr=""
hnd=open("file.exe","rb")
if hnd !=-1 then
char=getc(hnd)
while char !=-1 do
  filestr&=char
  char=getc(hnd)
end while
close(hnd)
end if

If you have a large file, it does cost a lot of time because of the
"filestr&=char" instruction, but which files are that big.

Or if you really want speed, try to use this information for an
asm/machlang program.
INT 21 3D-- - DOS 2+ - "OPEN" - OPEN EXISTING FILE
INT 21 42-- - DOS 2+ - "LSEEK" - SET CURRENT FILE POSITION
INT 21 3F-- - DOS 2+ - "READ" - READ FROM FILE OR DEVICE
INT 21 48-- - DOS 2+ - ALLOCATE MEMORY (LowMem)
INT 21 49-- - DOS 2+ - FREE MEMORY
INT 31 FF0B - CauseWay - "GetMem" - ALLOCATE BLOCK OF MEMORY
INT 31 FF0C - CauseWay - "GetMem32" - ALLOCATE BLOCK OF MEMORY (32-bit)
INT 31 FF0F - CauseWay - "RelMem" - RELEASE PREVIOUSLY ALLOCATED MEMORY
INT 21 3E-- - DOS 2+ - "CLOSE" - CLOSE FILE

Open the file, seek the end (Can't find a getfilesize function),
calculate the size, set to beginning
allocate mem, read till size, close file, DoSomething, freemem.


Bye,
PQ

>From: Jiri Babor <J.Babor at GNS.CRI.NZ>
>Every time I trip over the get_bytes() function, I get a feeling
>Robert wrote it in a darker moment of his life, included it in get.e
>when he was not quite himself, and he has not looked at it since...
>
>When I want maximum speed, I determine the size of the file first,
>create a buffer and read the bytes using a simple for loop:


________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu