Re: Faster way to write in a file
- From: Mark Bluemel <mark_bluemel@xxxxxxxxx>
- Date: Wed, 13 Feb 2008 13:38:55 +0000
LilacSkin wrote:
Hi,
Currently, I write an signed long long in a file with the fprintf
function:
No. You don't. You write the textual representation of the signed long
long value to the file. I will return to this point shortly.
signed long long * pData = NULL;
unsigned long long k = 0;
unsigned long DataAvail = 0 ;
pDataRx = (signed long long *) malloc ( sizeof(signed long long ) *
(65536*16*8) / 8);
for ( k = 0; k < DataAvail/8; k ++ ) {
fprintf ( pFilec, "%lli\t", pData[k]);
}
This snipped code is clearly incomplete, so tells us virtually nothing.
pDataRx is undefined. DataAvail is 0, so the loop will not be entered...
The problem is that function is very very slow !
Compared to what? How do you know?
In several forums, I saw that fwrite function is better,
Than what? In what way? Do you know (by measuring) that fprintf is the
cause of your problem?
As I pointed out above, fprintf is converting your signed long long
values to their textual representation. fwrite can't do that - it would
write the internal binary representation of the data.
I suppose you could write your own single-purpose function to convert
signed long long values into text and write that text with fwrite, and
that may perform better than fprintf...
but I don't know how to use it.
It (fwrite) is a simple enough function which is documented in the
standard and any good text.
Can you help me, please ?
You'd need to give us more information about the problem before we can
help you with the solution.
.
- References:
- Faster way to write in a file
- From: LilacSkin
- Faster way to write in a file
- Prev by Date: Re: Faster way to write in a file
- Next by Date: Re: Faster way to write in a file
- Previous by thread: Re: Faster way to write in a file
- Next by thread: Re: Faster way to write in a file
- Index(es):
Relevant Pages
|