views:

4015

answers:

10

I have a need to find the best library to compress in memory data. I am currently using zlib but I am wondering if there is a better compression library; better in terms of performance and memory footprint.

It should be able to handle multiple files in the same archive.

I am looking for a C/C++ library.

Performance is the key factor. The files that are being compressed are small to large XML files.

+7  A: 

Most libs have a C API rather than C++. You can look at lzo, which is fairly fast but not as good in terms of compression ratio.

http://www.oberhumer.com/opensource/lzo/

Compression tools shoot-out: http://compression.ca/act/act-summary.html

EDIT: More details about lzo (from its website, thanks Chris for correcting the link)

  • Requires no memory for decompression.
  • Compression is pretty fast.
  • Requires 64 kB of memory for compression.

Note that lzo works on memory buffers, so you'll have to handle the conversion to/from files yourself.

Also note that lzo is GPL which may be a problem, depending on your application.

rlerallut
LZO decompression is blazing fast, I've been told, compared to zlib. And it's worth noting that commercial licenses can be obtained. Lots of games use LZO commercial licenses.
Dan Olson
Also note that LZO compress a file. It doesn't handle archives by itself.
Wernight
+4  A: 

Here is a comparison table and here is another one, and I belive some of the tools have SDKs available...

epatel
+1  A: 

Here is a succintly written Linux Journal article from 2005 which seems to declare LZMA the winner for transferring files over a network. The results are based on percentage increase in 'effective bandwidth'.

If you need a small, fast compression library to increase the effective bandwidth of an application, then you should check out LZMA.

You'll see LZMA beating out both zlib and LZO... that said, last time I checked (2-3 years ago) the SDK was crap because it was literally extracted from 7zip and wasn't designed as a library... and for projects that required compression I used zlib because of the various client-friendly APIs available.

ceretullis
yes, LZMA produces nice compression ratios... but is it fast? From wikipedia description it would seem unlikely it'd be faster than gzip (deflate).
StaxMan
LZMA is fast. Gzip is ever so slightly faster, but LZMA has better compression ratios.
ceretullis
@StaxMan: Also, I can't believe that you would make a judgment call based on your reading a description of the algorithm versus a comparative benchmark of the algorithm.
ceretullis
A: 

Look at qlz lib ( QuickLZ ) it provides on GPL license , and it is open source

+3  A: 

In all reality, you have to decide what you want. Speed, or compression ratio. You can't have both...

In my findings, zlib is probably the best out there in terms of memory foot prnt, and speed, along with a decent compression ratio. There ARE faster ones out there, but how much compression do you need? LZ77/LZMA is probably right up there with deflate as an algorithm, however, I'm not sure of it's memory usage. I know it can and will compress files better than deflate...

There are tons of ways to handle this, so I'd figure out exactly what you have to accompolish first, THEN pick an algorithm to go with. And since you already mentioned you are compressing XML, I'd stick to algorithm data that shows text operations, and not focus so much on binary or any other data being compressed.

LarryF
+2  A: 

http://www.oberhumer.com/opensource/lzo/ is faster (twice as fast i believe) than zlib and compresses 10% worse

Ronny
+1  A: 

The best way is looking at a benchmark site, that display the cpu time without i/o. Ex. compressionratings

bill
A: 

try QuickLZ www.quicklz.com

Bartosz Wójcik
A: 

Checkout freearc.org . It is very fast but at the same time gives a higher compression ratio than RAR/7z/ZIP/GZ etc.YOu can directly use the source code for programming.

Unni
A: 

zlib and gzip, while not being the fastest to decompress, are pretty good overall and they have usually good GUI tools.

I don't know much about those two libraries performance comparison but the underlying library is zlip for ZIP archive handling.

Wernight