TITLE: why is there no renew or realloc in C++ (Newsgroups: comp.std.c++, 23 Jan 97) MIKAEL: d96-mst@nada.kth.se (Mikael Ståldal) writes: >Why aren't there any realloc() like thing for new/delete? CLAMAGE: stephen.clamage@Eng.Sun.COM (Steve Clamage) This question has been raised and discussed to death many times in this newsgroup. A "re-new" operation would have to do something like this, assuming you are asking for more space: 1. allocate enough space for the new array 2. copy-construct each old object into the new array in order. 3. destroy each old object in reverse order. 4. delete the old array 5. fill the remainder of the new array by constructing new objects with the no-argument constructor (if there isn't one, the re-new is illegal). The main original reason for not providing a "re-new" was that you would normally prefer to write a more efficient special-case version yourself. In addition, copying the object and destroying the original might not be the proper thing to do (it might hold a resource that would prevent copying it), but a general-purpose "re-new" has no choice but to use the above algorithm. Another reason was that you should not be creating C-style resizeable arrays of class objects anyway. Create (if you must) arrays of pointers to unmoving objects, and you can use malloc/realloc/free for those. A newer reason is that the standard library now provides a number of alternatives to C-style arrays, and you should use those instead, particulary since they directly support resizing.