multiple buffered input streams from single file while writing to that file?
I'm tackling a sorting problem that involves sorting a file that is larger
than main memory. The first phase generates an intermediate file whose
size is the identical to the original input file but that contains some
number of locally sorted sub-sections.
The second phase merges these sub-sections back into a single sorted list.
Instead of creating a third file to contain the single sorted list I would
like to overwrite the intermediate file that I'm reading from as I'm
reading from it.
Additionally, I'd like to maintain separate read buffers for each input
stream (each of which is reading from some offset into the intermediate
file).
I know I can use fopen() and fseek() to create multiple buffered read-only
input streams. However, the contract for fopen() stipulates that calling
it on a file in "w" mode sets the file's size to zero if it already
exists. I need it to not alter the file's size since I'm still reading
from it in multiple places.
Is there a straightforward way to accomplish this using fopen() & fseek()?
Or am I going to need to use open() and manage my own read/write
buffering?
No comments:
Post a Comment