我在开发项目中遇到网络传输需要传输数据,但对于数据的大小有严格的控制,请问能否对内存中的数据进行压缩,如果可以的话,该怎么压缩?我以前一直没接触过,另外,压缩比怎么样?多谢了!急用!!!!

解决方案 »

  1.   

    利用ZIP库进行压缩和解压缩 
    http://www.vchelp.net/vchelp/zsrc/zip_func.zip
    http://www.vchelp.net/vchelp/file2003_3/GzipHelper_demo.zip
      

  2.   

    可以在内存里压缩,最常见的是huffmann算法压缩
      

  3.   

    我发现Gziphelper_demo中的例子好像并不能真正的压缩数据,因为我在使用过程中我发现如下: float ftemp[10] = {12.11,13.123,234.445,112,234.232,23.3334,222.345,232.56878,23.456,3214};
     CA2GZIP gzip((char * )ftemp,40);  // do compressing here;
     LPGZIP pgzip=gzip.pgzip;  // pgzip is zipped data pointer, you can use it irectly
     int len=gzip.Length;      // Length is length of zipped data;
     char lptemp[70];
     for(int j = 0 ; j <55 ; j++)
     {
    lptemp[j] = *((char *)gzip.pgzip + j);
     }
       CGZIP2A plain((LPGZIP)lptemp,len);
     char *pplain=plain.psz;    // psz is plain data pointer
     int  aLen=plain.Length;    // Length is length of unzipped data.  printf("Size=%i  %s",aLen,pplain);
    //如上所示,为什么我在测试时要取出gzip.pgzip中超过50个字节进行解压缩
    //才能解的完整,这样的话数据占用的内存块反而要大了?我们每次只能传送
    //210个字节,请问有无办法解决此类数据压缩问题?