Subj : Re: realloc() issue on C++ To : borland.public.cpp.borlandcpp From : maeder Date : Sun Mar 20 2005 05:10 pm "Jose Mauro" writes: [please wrap lines] > There are a short and efficient way to implement the "C" realloc > function (where the previous content is copied to the new location > if necessary) in C++ ? realloc() is also a C++ function. Do you mean an equivalent to realloc() for memory obtained through ::operator new()? There is no such equivalent. > Stroustrup book's recommend the use of vector<> in this case, but > will be very cumbersome rewrite my code to use STL containers. > > Basically, i have a lots of "Object *" arrays allocated with "new > Object[size]", and i need reallocate these arrays to, say, > "Object[newsize]", preserving the initial contents. It's also very cumbersome to get these allocations (and, more importantly, the appropriate deallocations) correct, unless you use a container class, isn't it? > My difficulty is that initial array "size" is not know (not in > scope) ate the reallocation point, for permit a memory copy. Another point in favor of std::vector. .