I've just come upon something that I had never thought of before: can realloc() be used on a ptr that was assigned by the new opperator? And if so, will the opperator delete function correctly?
Printable View
I've just come upon something that I had never thought of before: can realloc() be used on a ptr that was assigned by the new opperator? And if so, will the opperator delete function correctly?
I can't quote a definate answer for you, but I would strongly caution against doing this even if your compiler will allow it. Write a realloc function that uses new to allocate a larger buffer, memcpy, and delete the original.
Roger C. Scudder Jr.
Annance Consulting
Wayne, Pennsylvania, US
The answer is "don't do it". realloc() and new() are different things that are not to be mixed together. The new() calls constructors, while realloc has no idea of objects or constructors.
You can't mix a call to new() with free(), or malloc() with delete(). The same thing goes with new() with realloc()/calloc().
Regards,
Paul McKenzie