kreuzerkrieg
kreuzerkrieg

Reputation: 3219

Setting up and using zlib properly

I'm playing around with zlib and after reading the zlib_how I still have couple of questions. As I understand, the deflateInit should be called before calling any deflate() which is ok, but what happens when I have an intention to reuse the same stream more than once?

Should I call deflateEnd each time I finish compression and then reinitialize every time the compression is called with additional call to the deflateInit? Whats about internal buffers dynamic allocations?

I see that init and end malloc/free a lot, could it be configured in such a way internal buffers will be reused between calls?

Upvotes: 0

Views: 420

Answers (1)

Mark Adler
Mark Adler

Reputation: 112219

You should use deflateReset() instead of deflateEnd() followed by deflateInit(), in order to avoid unnecessary free()'s and malloc()'s.

You should also read the documentation in zlib.h, where you would have discovered this.

Upvotes: 4

Related Questions