R
Rajorshi Biswas
Hi folks,
Suppose I have a large (1 GB) text file which I want to read in
reverse. The number of characters I want to read at a time is
insignificant. I'm confused as to how best to do it. Upon browsing
through this group and other sources on the web, it seems that there
are many ways to do it.
Some suggest that simply fseek'ing to 8K bytes before the end of file,
and going backwards is the way. In this case, am I guaranteed best
results if I fseek 8192 bytes behind my last position simply because
BUFSIZ = 8192 ? In other words is 8192 an optimal number ?
Others suggest that mmap'ing some 20-30K at a time into RAM is the way
to go... (but why 20-30K) ?
Another twist in the tale is that my program must be as portable as
possible. So I'm wondering whether mmap'ing would be viable at all -
but if it works fine on *X and Win (does Win even have mmap or an
equivalent ?), then it would be okay.
Any ideas on how to optimize for speed? I'll head off to do some
profiling on Linux and WinXP.. but it needs to be as portable+fast on
as many OS's as possible - so I need you guys' expertise
Thanks in advance,
Raj
Suppose I have a large (1 GB) text file which I want to read in
reverse. The number of characters I want to read at a time is
insignificant. I'm confused as to how best to do it. Upon browsing
through this group and other sources on the web, it seems that there
are many ways to do it.
Some suggest that simply fseek'ing to 8K bytes before the end of file,
and going backwards is the way. In this case, am I guaranteed best
results if I fseek 8192 bytes behind my last position simply because
BUFSIZ = 8192 ? In other words is 8192 an optimal number ?
Others suggest that mmap'ing some 20-30K at a time into RAM is the way
to go... (but why 20-30K) ?
Another twist in the tale is that my program must be as portable as
possible. So I'm wondering whether mmap'ing would be viable at all -
but if it works fine on *X and Win (does Win even have mmap or an
equivalent ?), then it would be okay.
Any ideas on how to optimize for speed? I'll head off to do some
profiling on Linux and WinXP.. but it needs to be as portable+fast on
as many OS's as possible - so I need you guys' expertise
Thanks in advance,
Raj