How to write binary data to a file using buffer?

L

Lambda

I'd like to write compressed data to a file.
To improve performance, I want to use buffer.

I read some books, they all talk about 'character' stream.
But I think compressed data should be binary.

And, what buffer size if optimal?
How can I set the buffer size?

I need to checkpoint the buffer when
1) the buffer is full.
2) I have put all the data to the buffer.

Should I use standard library or boost?
 
M

Michael DOUBEZ

Lambda a écrit :
I'd like to write compressed data to a file.
To improve performance, I want to use buffer.

[snip]
And, what buffer size if optimal?

That depends on your architecture, the algorithm you use ...
How can I set the buffer size?

You cannot but you can set the buffer to use with a call to
streambuf::pubsetbuf().
I need to checkpoint the buffer when
1) the buffer is full.

You can overload streambuf::eek:verflow()
2) I have put all the data to the buffer.

I don't think you can know that but perhaps at flush() time.
Should I use standard library or boost?

Boost.IOstream already provides compression and decompression in the
zlib, gzip and bzip2 formats. It would save you time. Using their
generic stream implementation might be a good idea; I don't know.

For more information about streambuf, see:
http://www.cplusplus.com/reference/iostream/streambuf/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top