Zlib compression for Windows Mobile

Source: Internet
Author: User

Preface:
In the current mobile phone application, compression technology may not attract much attention, but we can note that when the mobile phone communicates with the server, speed and stability are very important, in this phase, if we send the original file (or the original content) directly to the server, it will not only consume a lot of traffic (when the current traffic fee is not cheap, this situation can be avoided as much as possible), and the transmission speed is slow, the time consumed is long, and may also produce a series of shortcomings such as incomplete transmission. Therefore, if we adopt the compression technology to compress the content to be transmitted to the server, we can reduce the amount of data transmitted, reduce transmission time, and improve data stability!

 

Article introduction:
Zlib is used for data compression. The size of the compressed content and the transmission time are compared. the time consumed by compression and decompression on the terminal and server is temporarily ignored.

Test Platform:
VS 2005 + WM 6.0

Development language:
C ++

Body:
1. Download zlib package: http://www.tenik.co.jp /~ Adachi/wince/zlibce/index.html. Select the third item zlib for WindowsCE ver.1.1.4 (with binaries ).
2. After downloading the file to the local computer, unbind it. In the zlibce directory, there are header files zconf. h and zlib. h, and the library file zlibce. Lib under zlibce \ wce400 \ armv4i.
3. Create a smart device project under vs2005 and set it as a dialog box project.
4. Copy the header file and library file mentioned in step 1 to the project folder and add the above files to the project.
5. Add the following code to the header file of the dialog box to load the library file and header file into the project:
# Include "zlib. H"
# Pragma comment (Lib, "zlibce. lib ")
6. copy a file, such as test.txt, to the my documentsdirectory on the mobile phone, and the test.txt file in the previous test is 92.8 kb.
7. Add the following code to the oninitdialog function:
Read files:

int nLen;  char *pBuf;  CFile cf;  cf.Open(L"\\My Documents\\test.txt", CFile::modeRead);  nLen = cf.GetLength();  pBuf = new char[nLen];  cf.Read(pBuf, nLen); 

Compression:

gzFile zipFile = gzopen("\\My Documents\\test.gz", "wb");  gzwrite(zipFile, (voidp)pBuf, nLen);  gzclose(zipFile);

8. Start debugging

 

Summary:
Before compression, the size of the text file is 92.8 kb, and the size of the compressed file is 15.3 kb. The compression ratio is close to, and the time sent to the server is compared, the time consumed to send data to the server before compression is 33285 ms, and the time consumed to send data to the service after compression is 7214 Ms. It can be seen that the sending time is greatly reduced, which is conducive to establishing a high-speed and stable communication environment.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.