Is zLib Worth it? Are there other better suited compressors?
I am using an embedded system. Frequently, I have only 3MB of RAM or less available to my application. So I am considering using zlib to compress my buffers. I am concerned about overhead however.
The buffer’s average size will be 30kb. This probably won’t get compressed by zlib. Anyone know of a good compressor for extremely limited memory environments?
However, I will experience occasional maximum buffer sizes of 700kb, with 500kb much more common. Is zlib worth it in this case? Or is the overhead too much to justify?
My sole considerations for compression are RAM overhead of algorithm and performance at least as good as zlib.
LICENSE: I prefer the compressor be licensed under BSD, zLib, or equivalent license.
If you initialize zlib with
lm_init()with1,2, or3, thedeflate_fast()routine will be used instead ofdeflate(), which will use smaller runtime buffers and faster algorithms. The tradeoff is worse compression. It is probably worth it.If you compile zlib with
SMALL_MEMdefined, it will use smaller hash buckets when hashing input strings. The documentation (indeflate.c) claims:Hopefully, these two techniques combined can bring zlib into range with your application. It’s a ubiquitous standard, and being able to re-use well-worn components may be worth sacrifices elsewhere in the application. But if you know something about the distribution of your data that allows you to write your own compression routines, you may be able to do better, but you can drop zlib in place quickly — writing and testing your own might take more time.
Update
Here’s some output on a zlib built with
SMALL_MEM, using different compression level settings, on the first 600k file I found:The entire
gzipprogram takes around 2.6 megabytes of memory, regardless of the compression level asked for; perhaps just using the specific functions you need rather than the entiregzipprogram would bring that number down some, but it might be too expensive for your little machine.