delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/08/09:45:48

From: "DeHackEd" <Not DOT given AT out>
References: <bWLoegW7sFse-pn2-rXzsb45p63Iq AT portA20 DOT Generation DOT NET>
Subject: Re: NEW, DELETE and realloc()
Date: Sun, 8 Mar 1998 09:41:54 -0500
Lines: 39
Message-ID: <eGjjfAqS9GA.243@upnetnews02.moswest.msn.net>
Newsgroups: comp.os.msdos.djgpp
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

I'm not sure exactly what it would do, but you CAN write your own new and delete
operators like this:

void *operator new(size_t size)
{
    // commands go here
    return malloc(size);
}

// This one creates an array
void *operator new[](size_t size, size_t number)
{
    // you get the idea
    return malloc(size*number);
}

void operator delete(void *data)
{
    // stuff
    free(data);
}

This would work, though it may not be the most effective way. See if you can
inline it (I havn't tried) and put it in a header file.
--
"DeHackEd"

EMail address not given out due to low-life spammers.
Gili wrote in message ...
>Hello,
>
> Is it possible to use realloc() on memory allocated using NEW? 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?
>
>Gili


- Raw text -


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