tha_incredible_bo
asked on
C - fast Searching for a string in a textfile
hi folks,
i'm developing with borland c++ 4.52 under nt 4.0 but the project is compiled as an easywin 16-bit application.
is it possible to open a very large textfile (2-4 GB) and is so how can i find a certain string-token (e.g. a filename) as fastest as it can be? is this the right way or are there any other opportunities to do that, which lead to a better performance?
i'm developing with borland c++ 4.52 under nt 4.0 but the project is compiled as an easywin 16-bit application.
is it possible to open a very large textfile (2-4 GB) and is so how can i find a certain string-token (e.g. a filename) as fastest as it can be? is this the right way or are there any other opportunities to do that, which lead to a better performance?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Well, C is a very small language but it comes with an extensive run-time library (it is either linked statically to your program or dynamically - as a DLL). This library has many functions that deal with files. Those can be categorized into:
1. High level: fopen(), fread(), fwite(), etc.
2. Low level: open(), read(), write(), etc.
Now, those functions try to be efficient for the *general case* by using caching, bufferring, etc. However, if you only want to access a file sequentially (open it, read it, close it) you can save some unnecessery (in your case) overhead by using the underlying OS functions instead. In the case of Win3.x those are _lopen(), _hread(), _hwrite(), etc.
1. High level: fopen(), fread(), fwite(), etc.
2. Low level: open(), read(), write(), etc.
Now, those functions try to be efficient for the *general case* by using caching, bufferring, etc. However, if you only want to access a file sequentially (open it, read it, close it) you can save some unnecessery (in your case) overhead by using the underlying OS functions instead. In the case of Win3.x those are _lopen(), _hread(), _hwrite(), etc.
ASKER
thanks for your answer. Unfortunately the records are not with fixed length so that the work to handle them is a little bit difficult. Allright I think this will cost some time for me.
If you'd be so kind will you please explain what you mean with using OS commands directly and which ones to use (instead of C run-time functions)?