C read part of file into cache

Posted by Pete Jodo on Stack Overflow See other posts from Stack Overflow or by Pete Jodo
Published on 2012-11-26T22:56:09Z Indexed on 2012/11/26 23:03 UTC
Read the original article Hit count: 163

Filed under:
|
|
|

I have to do a program (for Linux) where there's an extremely large index file and I have to search and interpret the data from the file. Now the catch is, I'm only allowed to have x-bytes of the file cached at any time (determined by argument) so I have to remove certain data from the cache if it's not what I'm looking for.

If my understanding is correct, fopen (r) doesn't put anything in the cache, only when I call getc or fread(specifying size) does it get cached.

So my question is, lets say I use fread and read 100 bytes but after checking it, only 20 of the 100 bytes contains the data I need; how would I remove the useless 80 bytes from cache (or overwrite it) in order to read more from the file.

© Stack Overflow or respective owner

Related posts about c

    Related posts about file