Chinaunix首页 | 论坛 | 博客
  • 博客访问: 113558
  • 博文数量: 15
  • 博客积分: 2010
  • 博客等级: 大尉
  • 技术积分: 425
  • 用 户 组: 普通用户
  • 注册时间: 2007-04-01 14:51
文章分类

全部博文(15)

文章存档

2013年(4)

2011年(1)

2010年(2)

2009年(2)

2008年(6)

我的朋友

分类: C/C++

2008-08-25 13:40:38

使用方法:
包含zlib.h
连接时指明libz.so路径
compress,compress2为一次将所有串传入的压缩方法
int compress (Bytef *dest,   uLongf *destLen,
                                 const Bytef *source, uLong sourceLen);
按照默认级别6压缩字符串
source,输入字符串,要求以‘\0'结尾,sourceLen = strlen(source)
dest 输出字符串,预先分配的空间,在source很短,只有几个byte时,长度需要比source长12个字节
一般情况,可以比较短。一般的压缩率是2~5。
返回值
     compress returns Z_OK if success, Z_MEM_ERROR if there was not
   enough memory, Z_BUF_ERROR if there was not enough room in the output
   buffer.
zlib.h:
#define Z_OK            0
#define Z_STREAM_END    1
#define Z_NEED_DICT     2
#define Z_ERRNO        (-1)
#define Z_STREAM_ERROR (-2)
#define Z_DATA_ERROR   (-3)
#define Z_MEM_ERROR    (-4)
#define Z_BUF_ERROR    (-5)
#define Z_VERSION_ERROR (-6)
int compress2(Bytef *dest,   uLongf *destLen,
                                  const Bytef *source, uLong sourceLen,
                                  int level);
增加压缩级别参数level (1,...,9)

int uncompress (Bytef *dest,   uLongf *destLen,
                                   const Bytef *source, uLong sourceLen);
统一解压缩函数,注意传出串的长度
返回值:
     uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
   enough memory, Z_BUF_ERROR if there was not enough room in the output
   buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete.
  
其他的使用方法见解压缩后的文件example.c
缓冲区设定方法:
1。修改zlib.h的默认值
2。编译时指定
   -DMAX_WBITS=15 -DMAX_MEM_LEVEL=8(默认值)
   DMAX_WBITS,窗口宽度,15似乎是最大的了,再高会出错.目前这个值是最好的.
   DMAX_MEM_LEVEL 最大是8,小的话对性能有负面影响
  
分步压缩方法:
  将串逐段传入,依次压缩,
   第一个例子便是.
  
  
 
阅读(3505) | 评论(1) | 转发(0) |
0

上一篇:cublog的缺点

下一篇:LZ77压缩算法简介

给主人留下些什么吧!~~

chinaunix网友2008-12-31 09:41:03

Welcome back to The Queue, WoW Insider's daily Q&A column where the WoW Insider team answers your questions about the World of Warcraft. The above video is a video that has been posted very, very early in the Wrath beta, possibly even the alpha. So while the video labels the armor as Tier 7, Oh! I got a question. What the heck is Apothecary Putress wearing on his head, and where can i get one? Watch the video and found out!