Re: Reading a binary file

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

PQ wrote:

>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 <snip>

I actually do not see what *your* problem is, since you almost answered
your own question. Almost. Your code also has an extra test (char !=
-1) and an extra assignment (char = getc(hnd)). It all adds up to a
lot of unnecessarily wasted time, especially if you are in a hurry.

> ... but which files are that big.

Well, what do I say...

PQ then pasted about a dozen lines of interrupt info from some
"PC Programming for Beginners" and offered the following advice:

>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.

Contrast that with my stupid suggestion! Except PQ is, presumably,
also poking the read values into memory, and these will have to be
somehow retrieved later. Unless, of course, PQ has already forgotten
the original Brian's question : "Is there an easier/faster way to read
in a binary file to a *sequence* in one shot?" (my emphasis)

PQ, I hope I have answered your questions, but if it is just an
argument, that you want, forget it.

jiri

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

Search



Quick Links

User menu

Not signed in.

Misc Menu