Click to See Complete Forum and Search --> : memory allocation in c++
binaryDigit
12-10-2000, 09:10 AM
ok in c you use malloc, calloc, realloc, and free.
in c++ you use new and delete.
is there something like realloc in c++?
------------------
http://home.earthlink.net/~pebice/philLinux.html (http://home.earthlink.net/~pebice)
Glaurung
12-10-2000, 09:15 AM
It's all there: malloc, calloc, realloc, free, etc. It's in stdlib.h or cstdlib. The use of it isn't encouraged, though.
binaryDigit
12-10-2000, 10:34 AM
i realize that i could use stdlib.h
if i'm not mistaken the header for memory allocation in c++ is new.h
i just wanted to know if there was a function in c++ that would do the same as realloc.
this may be way off, and i'll look at it more when i get to a linux box, but doesn't the new function use malloc to allocate memory and if it does couldn't i just make a function that does the re-allocation for me.
------------------
http://home.earthlink.net/~pebice/philLinux.html (http://home.earthlink.net/~pebice)
Strike
12-10-2000, 02:26 PM
From the C++ specification:
If you feel the need to use realloc(), consider relying on a standard container instead; doing that is usually simpler and just as efficient.
And yes, there's only new and delete and yes they are in the <new> header.
The new function probably does use malloc() to allocate memory - you think most of the C++ stuff wasn't written in C?
[This message has been edited by Strike (edited 10 December 2000).]
A_Lawn_GNOME
12-10-2000, 03:04 PM
C++ was originally just a preprocessor for C.
My Java prof did a whole history of computer languages. Anyone ever use PL/1? Supposedly they tried to make it the language to end all languages. It flopped cuz it was too complex. COBOL took over and so on and so on.
Kinda interesting.