Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

caching files

Status
Not open for further replies.

tokra

Technical User
Feb 20, 2003
45
0
0
GB
I am processing files of our SAN, to minimize network load and load on the SAN (it is an issue in my enviornment) I want to cache the entire file to memory when it's opened. Writing my own file class is what I'm doing right now, but I am finding out how much of a pain it is. The file is part ASCII and part binary
Questions:
1:Is there a way to make the STL fstream chache the entire file upon opening, if so how can I read a line w/ get line containing bad characters like \0
2:Is there another tested solution already out there that anyone can recommend ?
3:Do you have any implementation tips right now im using a std::list of a
Code:
#define chunksize 1000000
struct chunk
{
char data[chunksize];
long nextchar;
long size;
};
to hold the file
are there any tips or gotchas i should be aware of?




WR
 
Not really a C++ technique

1) stat the file to find out how big it is
2) allocate the memory
3) fopen the file
4) fread the entire file
5) fclose the ile

Then you can do what you like with the allocated buffer.
 
Also look up CreateFileMapping. It is basically about memory mapped files. Not quite like Unix or as flexible as Unix but similar.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top