As already posted in this question C - fwrite binary file bigger than 4GB I need to write a binary file bigger than 4 GB. As learned through the first answer, I decided to develop my code making multiple calls to fwrite
.
My acquisition board has 2 FIFOs with dimension bufferLength12 = bufferLenght34 = 524288
Bytes. Each FIFO memory is linked with different channels, so when I start the acquisition I have data in both of them coming from different channels.
I want to do multiple readings, let's say 4*nacq
, from those FIFOs. And I want to use a different pointer for each cycle of acquisition.
So I have allocated the memory in this way:
v12 = (UINT64 *) calloc ( bufferLength12 , 4*nacq);
v34 = (UINT64 *) calloc ( bufferLength34 , 4*nacq);
Then the acquisition starts and I should pass, for each acquisition cycle, a different pointer in order to store the datas in RAM.
I make a cicle on the pointers in this way:
for ( p=v12,q=v34 ; p<v12+4*nacq && q<v34+4*nacq; p++,q++) {
ReadF(h, 0, (UINT64 *) p , bufferLength12 , NULL, 0);
ReadF(h, 1, (UINT64 *) q , bufferLength34 , NULL, 0); }
Then I try to write the data from the RAM to a binary file:
for ( p=v12,q=v34 ; p<v12+4*nacq && q<v34+4*nacq; p++,q++) {
fwrite( (UINT64 *) p, 8 , bufferLength12 , fd12);
fwrite( (UINT64 *) q, 8 , bufferLength34 , fd34);
}
fclose(fd12);
fd12=NULL;
fclose(fd34);
fd34=NULL;
If I run the code, I get a size of the binary file which is much bigger than then actual acquisition length. So I think that the pointers aren't been properly initialized.
If I plot the acquired data (just noise), I can see a lot of 0-values due to the allocation made with calloc
.
Any help would be greatly appreciated!