cembeddedzlibinflateminiz

zlib/miniz: how to configure inflate for very low memory usage?


I have an embedded system with low amounts of memory which needs to inflate zlib-deflated data packets coming from server-side. The deflation can use all the resources it wants, but for the inflation I'm limited to less than 5 kB. The deflated data packets are all 512 bits.

Because of the small packet size, I figured it's cheaper to do the inflation in one chunk and use buffers that are exactly as large as needed. But now I've been turning knobs in miniz for a while, trying to get the memory usage down and I'm finding that it's peaking around 5.5 kB for the simplest implementation I can make (slightly modified miniz example code). For now, I'm ignoring inflation speed since it seems to be fast enough for my requirements in any case. I'd just like to know how small it CAN be in theory/practice.

Things I've tried:

I've been reading up on Huffman coding to try and understand what these values do:

TINFL_MAX_HUFF_TABLES = 3,
TINFL_MAX_HUFF_SYMBOLS_0 = 288,
TINFL_MAX_HUFF_SYMBOLS_1 = 32,
TINFL_MAX_HUFF_SYMBOLS_2 = 19,
TINFL_FAST_LOOKUP_BITS = 1,
TINFL_FAST_LOOKUP_SIZE = 1 << TINFL_FAST_LOOKUP_BITS

But I can't say that I quite understand it. I can see they're directly related to allocated memory, but I'm not sure how to alter them correctly.

So I'm looking for suggestions for how to make the inflation use as little memory as possible. Alternatively suggestions for other libs that might be more suitable for my implementation.

Thanks :)


Solution

  • Look at puff.c as an alternative. It allocates on the order of 1KB off the stack.