News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

HeapRealloc - does it preserve the memory?

Started by TNick, August 24, 2006, 11:01:06 AM

Previous topic - Next topic

TNick

QuoteThe HeapReAlloc function reallocates a block of memory from a heap. This function enables you to resize a memory block and change other memory block properties. The allocated memory is not movable.
This is what Win32.hlp tell us about this function. But what I want to know and it doesn't tell me is: if I have something in that memory, can I be shure that the content will be preserved inside the new bounds?



Example:
I have allocated with HeapAlloc a block of memory of 10 bytes:
40, 50, 128, 47, 12, 88, 02, 77, 21, 49

If I set a new dimension to, let's say, 5, can I be shure that my memory will look like this:
40, 50, 128, 47, 12
... or not? ... or "not at all"?

drizz

win32.hlp is good for quick info, but you should really download the PSDK!

Quote from: PSDKHeapReAlloc is guaranteed to preserve the content of the memory being reallocated, even if the new memory is allocated at a different location. The process of preserving the memory content involves a memory copy operation that is potentially very large.
The truth cannot be learned ... it can only be recognized.

TNick


drizz

The truth cannot be learned ... it can only be recognized.

TNick


ToutEnMasm

Hello,
You are very lucky,
Just Type WriteToMemHeap in the search engine of this site and you have a sample.
But you can also ask winhelp for that,and also msdn
                                             ToutEnMasm

TNick

I didn't get it.. this wa a joke? WriteToMemHeap give this responses:
MSDN - There are no search results to display.
Win32.hlp - 0 rezults
This forum - 1 result in a topic HeapRealloc - does it preserve the memory?
:)

dsouza123

Using Advanced search WriteToMemHeap brings up 5 results/threads in 4 subforums.

All forums checked for searching.
The results are in :
The Campus
The Workshop (this thread)
The Laboratory
The GeneSys Development System (2 threads)

zooba

HeapRealloc in Google will probably give the MSDN (PSDK) page first.

Short answer is yes, it will preserve the values. If you are making the allocation larger the new bytes will be garbage or zero (depending on the HEAP_ZERO_MEMORY flag) and the base of the allocation may move, so make sure you pick up the return value. Generally it won't move if you're making it smaller, but it may find a more appropriate space for the smaller block, so use the return value anyway.

Cheers,

Zooba :U

TNick