- For individual users
- Instant access to solutions
- Ask your tech questions
- Start your 30-day Free Trial
Main Topics
Browse All TopicsI use zlib in my pocket pc application to compress and uncompress data that send it via socket to an desktop application server. My code for Uncopress is below :
The InByte parameter is the compressing data from server
The dwSizeInBytes is the size of InByte in bytes
When server compress the data i putting the original size bytes of data in a DWORD so the pda make the uncompress
The size of memory that i must allocate initially is :
DWORD dwUnCmpSize = (DWORD)(dwOrgSize + (dwOrgSize * 0.01) + 12);
and i allocated in pointer zStream
After the function 'uncompress' the dwUnCmpSize is smaller than initially and the zStream pointer has some dummy elements after the size of dwUnCmpSize
My Question is:
How can I manipulate the zStream pointer to size of the new dwUnCmpSize without allocate new memory block and copy the data?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: pgnatyukPosted on 2009-06-14 at 05:59:44ID: 24623286
I dont' know how to manipulate with the zStream pointer.
it is an old question and if noone answers, so here is the way I use Zlib.
It makes sense to allocate a big enough buffer only once and avoid these frequent memory allocation in the uncompress function. In your case without a C++ class, I'd add a static variable LPVOID and allocate a memory with malloc/realloc in an Initialize function (and delete in UnInitialize in the end).
It is possible to control the size of this memory block and if the requested size if bigger, you can allocate more memory with realloc. But this way will add new conditions into your function. I think that it is better just have enough memory allocated from the beginning.
If you work with a large amount of data, you can use VirtualAlloc.
If you work with a slow device, and the amount of memory you need is small, you can take it from the stack - just declare a static array in the cpp file.