Axarydax
Axarydax

Reputation: 16603

Simple compression in c++

we have a C++ MFC application and C# Web Service. They are communicating over HTTP, but as they are exchanging text data, compression will help a lot. But for some reasons, we can't use an external library.

We basically need to compress a byte array on one side and decompress it on the other side.

What should we use to compress our data? The best scenario would be if there is something in MFC/win32 api. Or is there some simplistic code with at most LGPL license that we could integrate into our project?

Upvotes: 2

Views: 1126

Answers (3)

Matthieu M.
Matthieu M.

Reputation: 299730

As has already been said, the zlib is probably what you are looking for.

There are several algorithms within:

  • The deflate and inflate pair
  • zlib itself
  • lzo

The simpler is probably lzo (I advise to pass the uncompressed size on the side), but zlib isn't very complicated either and the compression rate can be parameterized (speed / size trade off) which can be a plus depending on your constraints.

For XML data (since you were speaking of web services), LZO gave me a ~4x compression factor.

Upvotes: 3

John Carter
John Carter

Reputation: 55271

Can't you just switch on HTTP compression? http://en.wikipedia.org/wiki/HTTP_compression

Upvotes: 3

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798486

zlib has a very liberal license.

Upvotes: 1

Related Questions