Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!uunet!sdl.mdcbbs.com!alanb From: alanb@sdl.mdcbbs.com Newsgroups: comp.lang.c++ Subject: Re: proposal for new/delete extension Message-ID: <1991Jun26.103505.1@sdl.mdcbbs.com> Date: 26 Jun 91 09:35:05 GMT References: <19215@prometheus.megatest.UUCP> Organization: Shape Data Ltd. (McDonnell Douglas M&E, Cambridge UK) Lines: 33 Nntp-Posting-Host: shapeg Nntp-Posting-User: alanb In article <19215@prometheus.megatest.UUCP>, djones@megatest.UUCP (Dave Jones) writes: > > > I would like to describe to you a small language-extension which I think > would prove useful. First I will describe the problem to be solved. > > Occasionally, for the sake of efficiency, it is desirable to > allocate memory for new objects of a given class from a pool of preallocated > packets, sized by the sizeof() operator. It has been my experience that this > practice can improve the performance of some applications very significantly. > We therefore redefine the "new" and "delete" operators for the class. > > class Class1 { > char goodies[SIZE]; > public: > void *operator new(size_t); // ignores the size_t > void operator delete(void *); > // etc.. > }; > [Detail omitted] > Class1 *operator new(); > void operator delete(Class1*); Sounds plausible. As a workround, would the following work? void *Class1::operator new(size_t s) { // If default new doesn't work, Class2 needs to redefine operator new anyway if (s != sizeof(Class1)) return ::operator new(s); // Do fixed pool stuff here }