Reallocate memory 
Author Message
 Reallocate memory

Hi,

Does anyone know whether there is function in c++ as the
function realloc in c? How can I re-allocate memory when I
find the memory allocated by new is not enough?

Thanks in advance,
Andy



Mon, 28 Mar 2005 08:49:40 GMT  
 Reallocate memory

Quote:
> Hi,

> Does anyone know whether there is function in c++ as the
> function realloc in c? How can I re-allocate memory when I
> find the memory allocated by new is not enough?

You can't.

In many cases though, this means that you should probably be using
std::vector instead of allocating an array yourself.  std::vector takes care
of reallocating memory when necessary so you don't have to worry about it.

-cd



Mon, 28 Mar 2005 10:13:52 GMT  
 Reallocate memory

Quote:

> Does anyone know whether there is function in c++ as the
> function realloc in c? How can I re-allocate memory when I
> find the memory allocated by new is not enough?

You can't.  You have to allocate and copy.

It's been suggested that some kind of realloc should be added to
allocators in the next round of the standard so that the standard
containers can extend their current allocation on expansion (if
possible) instead of doing an allocate and copy.

--
Craig Powers
MVP - Visual C++



Mon, 28 Mar 2005 22:46:47 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Freeing reallocated memory

2. Reallocating memory without disturbing the original address

3. reallocating memory

4. dynamically reallocate memory for object derived from class without destroying the data

5. How to Reallocate memory ?

6. reallocating space for pointer to structs?

7. getting a reallocated string back

8. Allocating anf Reallocating in COM

9. Reallocating space for an array from VB

10. Reallocating a heap created by HeapCreate

11. REALLOCATE vs DEALLOCATE

12. Question: reallocating a 2 dimentional array

 

 
Powered by phpBB® Forum Software