::operator new() customization — ARM

ARM Jargon warning —
“the new-operator will call the function operator-new()” actually means
The new expression will call the function operator-new()

P60 ARM makes it clear that function operator-new can be overloaded — new-expression is not something you overload. Ultimately, op-new is really just a function and as such can be overloaded. The global qq{::operator new()} can be overloaded for class T, using T::operator new() [2]. Quite common and safe. See Scott Meyers and [[c++primer]]

Q: But can you overload the global  ::operator new()  ?
A: yes. P60 ARM Bullet point 2
A: yes. “Unlike class-specific new, global new is usually overloaded for debugging purposes. In some cases, however, you might want to overload global new and delete permanently, because you have a better allocation strategy or because you want more control over it.” according to [[C++InAction]] http://www.relisoft.com/book/tech/9new.html

[[c++TimesavingTechniques]] P128 has a rather simple yet practical replacement for global  ::operator new()

[2] the static method syntax. Class-specific Op-new() is implicitly static since you never call op-new on an existing instance to grab memory for a new instance.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s