Skip to main content
gamedev.net
🔒 Locked

Realloc and data integrity

Started by ShmeeBegek Jan 23, 2004 at 5:28 PM 3 replies 300+ views
Original Post
ShmeeBegek
ShmeeBegek
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
AIM ME: aGaBoOgAmOnGeR
SiCrane
SiCrane
The contents of the two blocks will be the same up to the minimum of the new and the old size of the buffer.
Namethatnobodyelsetook
Namethatnobodyelsetook
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.
chollida1
chollida1
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
CheersChris
VolkerG
VolkerG
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.