writing a file from buffer
I want to know what would be an efficient way of do it. I haven't written any code yet, i just have a couple of ideas. Here they go both (just an idea about how code would look like):
1.
To write entire buffer in one step like:
Code:
fwrite ( buffer , 1 , totalBufferSize , filePointer );
2.
To divide buffer into smaller parts, of 1024 bytes each.
This, requires to copy 1024 bytes from original buffer to a temporal one, and then
copy it to the image like:
Code:
int i;
int copyStartPosition; /* Position of original buffer where copy begins */
for ( i = 0 ; i < 1024 ; i++ )
{
tmpBuffer[i] = originalBuffer[i+copyStartPosition];
}
fwrite ( tmpBuffer , 1 , 1024 , filePointer );
Here i'm not counting on not all packages will have a regular size of 1024 bytes, the last
one could not have it.
Am i in the right way to solve this problem?