cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/07/21:15:34

From: "Luke Bishop" <lbishop AT calvin DOT stemnet DOT nf DOT ca>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: NEW, DELETE and realloc()
Date: 6 Mar 1998 20:28:28 GMT
Organization: The Zone
Lines: 24
Message-ID: <01bd4885$3d44a100$7348a5c6@technoid>
References: <bWLoegW7sFse-pn2-rXzsb45p63Iq AT portA20 DOT Generation DOT NET>
NNTP-Posting-Host: n072h115.thezone.net
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

> 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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019