压缩小块数据 [英] Compressing small piece of data

查看:141
本文介绍了压缩小块数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个缓冲区,让我们说4KB,包含JSON类似格式的数据。我需要添加明显更多的信息(最多让我们说3倍多),但我必须适应这个小块的内存。我正在考虑使用libZ来压缩文本,但恐怕它不会执行得很好,因为数据主要由一些独特的子字符串。在这种情况下你会推荐什么?
感谢,
Chris

I have a buffer of let's say 4KB, containing data in JSON-like format. I need to add significantly more information (up to let's say 3x more) to it, but I have to fit in this small chunk of memory. I was thinking about using libZ to compress text, but I'm afraid it will not perform well since the data consists mostly of some unique substrings. What would you recommend in this situation? Thanks, Chris

推荐答案

考虑一个包含多达32K字符串的固定字典出现在您的数据中。您可以使用 zlib deflateSetDictionary() inflateSetDictionary()在每一端(数据的发送方和接收方分别)在两端具有相同的字典。这可能会让你找到你想要的压缩。没有字典,你不太可能得到这样少量的数据的压缩。

Consider a fixed dictionary containing up to 32K of strings that you expect to appear in your data. You would use zlib's deflateSetDictionary() and inflateSetDictionary() on each end (the sender and receiver of the data respectively) with the same dictionary on both ends. That may get you the compression you're looking for. Without a dictionary, you are unlikely to get that sort of compression with such a small amount of data.

这篇关于压缩小块数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆