问题描述
我想使用 google-snappy,我做了一些简单的测试来熟悉这个库。我编写了以下程序:
#include <iostream>
#include "snappy/snappy.h"
int main(int argc,char *argv[]) {
static const char alphanum[] =
"0123456789"
"ABCDEFGHIJKLMnopQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
std::string string_data,string_data_temp;
for (int i = 0; i < 10; ++i) {
string_data += alphanum[rand() % (sizeof(alphanum) - 1)];
}
snappy::Compress(string_data.data(),string_data.size(),&string_data_temp);
std::cout << string_data.size() << std::endl;
std::cout << string_data_temp.size() << std::endl;
return 0;
}
所以基本上我生成一个随机字符串,然后压缩它并测量它的大小。真正有趣的是,当我运行程序时,string_data
的大小为 10,而压缩版本 string_data_temp
的大小为 12。这是什么解释?即使在随机字符串的情况下,压缩版本不应该最多是原始输入的大小吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)