realloc in case of new and delete operators

F

free2cric

Hi, As you know memory block assigned by malloc can be resized by
realloc with previously assigned data in the memory block intact. How
this to achieve in case
if the memory block is assigned with "new" operator.
thanks crick.
 
K

Karl Heinz Buchegger

free2cric said:
Hi, As you know memory block assigned by malloc can be resized by
realloc with previously assigned data in the memory block intact. How
this to achieve in case
if the memory block is assigned with "new" operator.

There is no way to do that with one simple call.

Allocate more memory
copy the old content to the new location
free the old memory

Or simply use a standard contained such as std::vector.
They do all of this automatically for you under the hood.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top