Next: Other Builtins, Previous: Object Size Checking, Up: Built-in Functions [Contents][Index]
GNU C++ provides builtins that are equivalent to calling ::operator new or ::operator delete with the same arguments. It is an error if the selected ::operator new or ::operator delete overload is not a replaceable global operator. For optimization purposes, calls to pairs of these builtins can be omitted if access to the allocation is optimized out, or could be replaced with an implementation-provided buffer on the stack, or multiple allocation calls can be merged into a single allocation. In C++ such optimizations are normally allowed just for calls to such replaceable global operators from new and delete expressions.
void foo () {
int *a = new int;
delete a; // This pair of allocation/deallocation operators can be omitted
// or replaced with int _temp; int *a = &_temp; etc.
void *b = ::operator new (32);
::operator delete (b); // This one cannnot.
void *c = __builtin_operator_new (32);
__builtin_operator_delete (c); // This one can.
}
These built-ins are only available in C++.