reallocate extra memory

R

Rahul

Hi everyone,

I had allocated from memory for a character array using the new
operator in cpp. Now i want to increase this allocation dynamically,
realloc() works with memory allocated by malloc(), does it work with
memory allocated by new? If not, is there any operator that can do the
same in c plus plus?

Thanks in advance ! ! !
 
G

Gianni Mariani

Rahul said:
Hi everyone,

I had allocated from memory for a character array using the new
operator in cpp. Now i want to increase this allocation dynamically,
realloc() works with memory allocated by malloc(), does it work with
memory allocated by new? If not, is there any operator that can do the
same in c plus plus?

No. The only thing you can ho with objects allocated with new is to
allocate a larger chunk and copy the original chunk's content.
 
K

Kai-Uwe Bux

Rahul said:
I had allocated from memory for a character array using the new
operator in cpp. Now i want to increase this allocation dynamically,
realloc() works with memory allocated by malloc(), does it work with
memory allocated by new? If not, is there any operator that can do the
same in c plus plus?

No, but you can use std::vector<char> instead of a raw pointer.


Best

Kai-Uwe Bux
 

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
474,176
Messages
2,570,947
Members
47,498
Latest member
log5Sshell/alfa5

Latest Threads

Top