C
chrisp
Hi, I have an application that appends to 40mb files, intermittently
this append operation takes a long time (8-30 seconds) to append 300k
of data.
When watching the application with task manager I notice that the
application writes 40mb of data when this occurs. (the size of the
file I'm appending to)
To ensure I wasn't writing 40mb of data I wrote a test program.
(attached below) which opens a file in binary append mode, writes some
data, and closes it.
Now here's where it gets weird.
If I run the test program, it takes less than a second, then I reboot
my laptop and try again, the first time I run it on the test file it
takes 8 seconds, and in task manager, it shows it wrote 40mb, the
second time, it takes 0 seconds and writes 300k
If I run the same test program, on another copy of the same file, it
works fine. Even if I reboot first.
I have defragemented my drive and uninstalled norton anti virus.
Any one got any idea what's going on ? Why is the operating system
writing 40mb of data some times for some files?
Code and log attached.
Running on windows xp professional 2002, sp 2, on an HP laptop.
-------------
Directory of C:\
05/10/2006 09:48 a.m. 40,655,238 Done.data
05/10/2006 09:47 a.m. 40,055,238 done.data3
C:\src\testadd\Debug>testadd \done.data3
Done it 0 seconds
C:\src\testadd\Debug>testadd \done.data
Done it 8 seconds
C:\src\testadd\Debug>testadd \done.data
Done it 0 seconds
-----------------------test program
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
int main(int argc, char *argv[])
{
FILE *f;
char bf[30003];
int start = time(NULL);
printf("Press return to start:"); gets(bf);
start = time(NULL);
f = fopen(argv[1],"ab");
fwrite(bf,30000,1,f);
fwrite(bf,30000,1,f);
fwrite(bf,30000,1,f);
fwrite(bf,30000,1,f);
fwrite(bf,30000,1,f);
fwrite(bf,30000,1,f);
fwrite(bf,30000,1,f);
fwrite(bf,30000,1,f);
fwrite(bf,30000,1,f);
fwrite(bf,30000,1,f);
fclose(f);
printf("Done it %d\n",time(NULL)-start);
printf("Press return to finish:");
gets(bf);
return 0;
}
this append operation takes a long time (8-30 seconds) to append 300k
of data.
When watching the application with task manager I notice that the
application writes 40mb of data when this occurs. (the size of the
file I'm appending to)
To ensure I wasn't writing 40mb of data I wrote a test program.
(attached below) which opens a file in binary append mode, writes some
data, and closes it.
Now here's where it gets weird.
If I run the test program, it takes less than a second, then I reboot
my laptop and try again, the first time I run it on the test file it
takes 8 seconds, and in task manager, it shows it wrote 40mb, the
second time, it takes 0 seconds and writes 300k
If I run the same test program, on another copy of the same file, it
works fine. Even if I reboot first.
I have defragemented my drive and uninstalled norton anti virus.
Any one got any idea what's going on ? Why is the operating system
writing 40mb of data some times for some files?
Code and log attached.
Running on windows xp professional 2002, sp 2, on an HP laptop.
-------------
Directory of C:\
05/10/2006 09:48 a.m. 40,655,238 Done.data
05/10/2006 09:47 a.m. 40,055,238 done.data3
C:\src\testadd\Debug>testadd \done.data3
Done it 0 seconds
C:\src\testadd\Debug>testadd \done.data
Done it 8 seconds
C:\src\testadd\Debug>testadd \done.data
Done it 0 seconds
-----------------------test program
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
int main(int argc, char *argv[])
{
FILE *f;
char bf[30003];
int start = time(NULL);
printf("Press return to start:"); gets(bf);
start = time(NULL);
f = fopen(argv[1],"ab");
fwrite(bf,30000,1,f);
fwrite(bf,30000,1,f);
fwrite(bf,30000,1,f);
fwrite(bf,30000,1,f);
fwrite(bf,30000,1,f);
fwrite(bf,30000,1,f);
fwrite(bf,30000,1,f);
fwrite(bf,30000,1,f);
fwrite(bf,30000,1,f);
fwrite(bf,30000,1,f);
fclose(f);
printf("Done it %d\n",time(NULL)-start);
printf("Press return to finish:");
gets(bf);
return 0;
}