Jeremy Coulter asked:

> I have been doing some data conversion for work last few
> days, and one thing I to do is searching for some text in
> a file, and thenget the offset to the text. (the file is
> binary not text)

> or is there a better/smarteer way to do it ?

After much mucking about with code that hand to handle buffers, overlapped
data between buttfer, and all the associated state engine stuff I change
all our code over to use memory mapped files. (Using an improved
mapfiles.zip available from the Delphi Super Page I think, I can send to
you if required as its only 16K of zip).

So now I just map an entire file into memory and walk it with a simple
pointer. This avoids any issues of boundaries and makes the code much
simpiler and faster as I can use pointer increments to walk about. And it
usues less memory as the memory mapping is all managed by the OS and you
get the dual advantages of utilising as much cache memory as you can be
spared, plus a minimal foot print if the OS decides that some other
program needs the RAM more.

Wrap this up in a TStream interface and you have a really useful way of
handling readonly files.

Cheers, Max.


---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"

Reply via email to