Any fast File read/write method?
-
Dear all, Anybody knows a fastest file read/write method? It is because i am doing a program and need to read/write a same file many many times, using CFile to read/write is very very slow. Any suggest method? Andy
There is also
FILE
structure for doing that but I don't know if it is faster than CFile. Mazy "The path you tread is narrow and the drop is shear and very high, The ravens all are watching from a vantage point near by, Apprehension creeping like a choo-train uo your spine, Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd -
Dear all, Anybody knows a fastest file read/write method? It is because i am doing a program and need to read/write a same file many many times, using CFile to read/write is very very slow. Any suggest method? Andy
-
An alternative is to use memory-mapped files, for which some examples can be found on the Microsoft knowledge base. There also exists a sample called ProcessWalker. The downside is that it only works on NT or higher (I believe). Alwin
Memory mapped files work for all Win32 operating systems.
Build a man a fire, and he will be warm for a day
Light a man on fire, and he will be warm for the rest of his life! -
Dear all, Anybody knows a fastest file read/write method? It is because i am doing a program and need to read/write a same file many many times, using CFile to read/write is very very slow. Any suggest method? Andy
why don't you try this in pure c? e.g.:
FILE *fp1;
char word[100];
char c;fp1 = fopen("yourfile.txt", "r");
do
{
c = fscanf(fp1, "%s", word); // read a word
DoSomethingWith(word);
}while (c != EOF); // until end of filefclose(fp1);
Bunburry
-
why don't you try this in pure c? e.g.:
FILE *fp1;
char word[100];
char c;fp1 = fopen("yourfile.txt", "r");
do
{
c = fscanf(fp1, "%s", word); // read a word
DoSomethingWith(word);
}while (c != EOF); // until end of filefclose(fp1);
Bunburry
A memory mapped file will still be faster because you will be accessing the file directly in memory. You will have a pointer that points directly to the buffer that contains the file.
Build a man a fire, and he will be warm for a day
Light a man on fire, and he will be warm for the rest of his life! -
Dear all, Anybody knows a fastest file read/write method? It is because i am doing a program and need to read/write a same file many many times, using CFile to read/write is very very slow. Any suggest method? Andy
I believe the multi-media IO functions provide the fastest file read/write performance on windows. Check out the mmioOpen function and all of its associated functions. In an app I developed a couple of years ago, my tests showed that mmio outperformed every other method. I don't have the stats for just how much, but it was enough to make a difference. My 2 cents. Matt Gullett