How to write files more faster in C
Just a thing i want to toy with:
Code:
#define ONE_GIGA 0x40000000
#define ONE_MEGA 0x100000
#include<stdio.h>
#include<stdint.h>
#include<stdlib.h>
int main()
{
FILE *f=fopen("big_file.dat","wt");
uint64_t i;
if(f==NULL)
{
exit(-1);
}
for(i=0 ; i < ONE_GIGA ; i++)
{
if(0 == i % ONE_MEGA)
{
printf("Created %ld.", (long)i / ONE_MEGA);
fflush(stdout);
printf("\r");
}
fprintf(f,"x");
}
printf("...Done\n\n");
fclose(f);
return 0;
}
this application writes one gig of 'x' in big_file.dat. The problem is that it writes them quite slowly. How can I improve my timing ? using fwrite would improve it?
I just want some ideas on how can I make file write more faster. Using sys calls will help ?