From: "Luke Bishop" 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: NNTP-Posting-Host: n072h115.thezone.net To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk > 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...)