Re: what is the difference between new and opeartor new.
On Feb 17, 12:16 pm, SG <s.gesem...@gmail.com> wrote:
On 17 Feb., 07:41, sukhpal <sukhb...@gmail.com> wrote:
class MyClass {
[...]
void *operator new(size_t size);
void operator delete(void *p);
void *operator new[](size_t size);
void operator delete[](void *p);
};
These ought to be static members. (!)
They are. Member allocation and deallocation functions are
always static, even if not declared as such. (Traditionally,
I've never seen them declared static, and wasn't even aware that
it was legal until recently. Logically, however, it's probably
a good idea to declare them static: you want them to be static,
and you know that they are, so why not say so?)
Unless you have a very good reason to mess with overloaded
operators new and delete you should avoid it. There are some
subtleties to it and you need to know how to do it correctly.
For example: You need to try allocating memory in a loop if
there is a "new_handler" installed.
You have to obey the required semantics. More or less; you're
supposed to use the loop, for example, but one reason you want
to provide a class specific allocator is to avoid the installed
new_handler for that class.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34