Sign in to follow this  
dynameat

c++ simple compression

Recommended Posts

hi, well I am using c++, and I am making a program that can compress a buffer. I tried looking online and in the forums for a simple compression library, but it seems that the topic is very complicated. I don't even know if what I have in mind is possible. the following code demonstrates what I would like to accomplish: [cpp] void main() { char* buf = new char[MAX] ; int size = MAX ; char* cmpbuf = NULL ; int cmpsize = 0 ; //the compression occurs here SimpleCompressFunc(buf, size, &cmpbuf, &cmpsize) ; //now cmpbuf points to an array of the compressed data, and cmpsize has the size of that array } [/cpp] now is there any library out there that provides such a simple mean of compressing and decompressing buffers?

Share this post


Link to post
Share on other sites
I'm not sure it's quite as simple as what you're looking for, but the zlib library (www.zlib.net) is probably about as good as you'll ever need. You could probably write a tiny little wrapper for it so that it does what you're looking for just by lifting their sample code.

Best part (at least in my opinion) is the license. It basically boils down to "do whatever you want with it", which is nice, especially if you want to sell your stuff, or even just keep it closed-source.

Share this post


Link to post
Share on other sites
The good news is that what you generally describe is literally THE way that compression libraries are generally handled. As was already mentioned, zlib is one such library, but there are MANY of them of varrying strength and practicality.

Share this post


Link to post
Share on other sites
It would be extremely benneficial for you to describe what kind of data you wish to compress. For example:

Is it raw pixel image data?
Is it text?
Is it an array of floating point values?
Is it an array of integers?
Is it a buffer containing executable code?
Is it a mixture of some of the above?

The best answer in terms of simplicity, speed, or compression ratio, depends on what it is you want to compress, and how important those factors are.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this