Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > realloc in case of new and delete operators

Reply
Thread Tools

realloc in case of new and delete operators

 
 
free2cric
Guest
Posts: n/a
 
      04-05-2005
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.
 
Reply With Quote
 
 
 
 
Karl Heinz Buchegger
Guest
Posts: n/a
 
      04-05-2005
free2cric wrote:
>
> 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.

--
Karl Heinz Buchegger
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
In which case, realloc returns NULL??? shahul Windows 64bit 3 03-30-2006 10:44 PM
Overloading class new and delete operators with parameters Douglas Peterson C++ 1 01-22-2005 08:33 PM
Program namespaces partitioning and new/delete operators GianGuz C++ 4 12-20-2004 03:15 PM
Overloading new and delete operators Nimmi Srivastav C++ 3 02-02-2004 07:20 AM
Overloading new[] and delete[]: how do they vary from new and delete? HeroOfSpielburg C++ 1 08-06-2003 03:58 AM



Advertisments