开发者

What would be the fastest way to compress streaming char arrays in text format using C?

I have very little experience with compression algorithms; my experience just comes from running the tar czvf command. Is there a way to compress a char array in C?

My main focus is speed and memory optimization. I'm receiving data from serial ports, and then writing them out to a log file right now. I want t开发者_JS百科o compress/encrypt the data before I write it to the log file because I have limited harddrive space. I am also storing the information in ASCII format, because I have to pack it with a timestamp. What method should I look into for compressing this information? Or is there some library I can look into to help?


zlib has already been mentioned in the comments. Since you mention ASCII, you might be interested in particular in the functions:

ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));


I have this lib bookmarked here, but I've never used it.

LZO is a data compression library which is suitable for data de-/compression in real-time. This means it favours speed over compression ratio.

LZO is written in ANSI C. Both the source code and the compressed data format are designed to be portable across platforms.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜