- 论坛徽章:
- 0
|
用zlib压缩后比源数据还大
压缩前的数据大小是16384;
压缩后是16395;
#include "zlib.h"
#include <stdio.h>
#include <windows.h>
#define MEMLEN 16*1024
int main()
{
unsigned char *sMem;
unsigned char *dMem;
unsigned char *tMem;
unsigned long dLen=MEMLEN, sLen=MEMLEN, tLen=MEMLEN;
int i;
int err;
int iRet;
unsigned int iStart, iEnd;
sMem = malloc(MEMLEN);
tMem = malloc(MEMLEN);
for (i = 0; i < MEMLEN; i++)
sMem = rand() % 256;
dLen = compressBound(sLen);
dMem = malloc(dLen);
iStart = GetTickCount();
err = compress(dMem, &dLen, sMem, sLen);
iEnd = GetTickCount();
printf("compress; time: %d; len=%d; err=%d \n", iEnd - iStart, dLen, err);
iStart = GetTickCount();
err = uncompress(tMem, &tLen, dMem, dLen);
iEnd = GetTickCount();
printf("decompress; time: %d; len=%d; err=%d \n", iEnd - iStart, tLen, err);
iRet = memcmp(sMem, tMem, MEMLEN);
printf("iRet: %d\n", iRet);
return 0;
} |
|
|