I'm working on a C project where we have to write some binary files in a Embedded Linux environment (2.6.37). Normally we are able to write the files in something like 200-300 ms, but eventually the file take up to 10 seconds to be written and we have no idea why - the occurrence is quite randomic with no special event happening in other parts of the system, such as in the UI app.
Either way we are revising or method to write to the file and doing some research on the web (here and here and here) we concluded that writing using native Linux code would be better then doing it pure C even though that may not end up helping much with our problem. For now we are writing in a way similar to this, that is, with these functions:
#include <stdio.h>
const unsigned long long size = 8ULL*1024ULL*1024ULL;
unsigned long long a[size];
int main()
{
FILE* pFile;
pFile = fopen("file.binary", "wb");
for (unsigned long long j = 0; j < 1024; ++j){
//Some calculations to fill a[]
fwrite(a, 1, size*sizeof(unsigned long long), pFile);
}
fclose(pFile);
return 0;
}
Well what I would like to know is which would be the native Linux way to do an equivalent operation (and in the fastest way possible)? The links mentioned only tell about copying files, not simply writing to them, so I suppose there might be more specific functions to be used.
Any help appreciated (as well as any tip regarding the original problem).