• Advertisement

Archived

This topic is now archived and is closed to further replies.

Realloc and data integrity

This topic is 5144 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m wondering whether or not the realloc function maintains the values of data (even in the case that a different pointer is returned than was passed to realloc). I''ve looked in the MSDN documentation on this issue and I have found nothing of pertinence. Thanks, ~SPH

Share this post


Link to post
Share on other sites
Advertisement
The contents of the two blocks will be the same up to the minimum of the new and the old size of the buffer.

Share this post


Link to post
Share on other sites
The data will be exactly the same, yes, but that doesn''t mean data integrity. Pointers pointing into the memory that you reallocated will become bad. Anything that will be pointed to should never go into a memory block you intend to realloc.

Share this post


Link to post
Share on other sites
How hard is it to write two lines of test code to see?? It will retain your data. You''ll never learn if you don''t try

Cheers
Chris

Share this post


Link to post
Share on other sites
Taken from the MSDN library:

The size argument gives the new size of the block, in bytes. The contents of the block are unchanged up to the shorter of the new and old sizes, although the new block can be in a different location. Because the new block can be in a new memory location, the pointer returned by realloc is not guaranteed to be the pointer passed through the memblock argument.

Share this post


Link to post
Share on other sites

  • Advertisement