Mail Archives: djgpp/1998/03/07/21:15:34
> Hello,
>
> Is it possible to use realloc() on memory allocated using NEW?
Actually, it is in DJGPP with whatever GCC I have, but you shouldn't do it
anyway, it probably doesn't stay the same...
> Is
> there a C++ equivilent? Also, is it possible to simply write my own
> NEW operator? If so, what does GCC do, simply reroute the command to
> malloc() and call that instead?
The NEW operator can be overridden, but it has a subtle bug which may not
be obvious. If your new operator cannot allocate memory and returns NULL,
your virtual function table is still written to the object (over the NULL
address) and your constructor is called. You can get around the
constructor problem by simply adding:
if(this==NULL)
return;
To the top of your constructor. But you should be careful with virtual
functions in these classes anyway (otherwise overwriting NULL...)
- Raw text -