Functions
The placement new functions are overloads of the non-placement new functions. The declaration of the non-placement new functions, for non-array and array new
expressions respectively, are:
-
void * operator new (std::size_t) throw(std::bad_alloc);
void * operator new (std::size_t) throw(std::bad_alloc);
The Standard C++ library provides two placement overloads each for these functions. Their declarations are:
-
void * operator new (std::size_t, const std::nothrow_t &) throw;
void * operator new (std::size_t, void *) throw;
void * operator new (std::size_t, const std::nothrow_t &) throw;
void * operator new (std::size_t, void *) throw;
In all of the overloads, the first parameter to the operator new
function is of type std::size_t, which when the function is called will be passed as an argument the amount of memory, in bytes, to allocate. All of the functions must return type void *, which is a pointer to the storage that the function allocates.
There are also placement delete functions. They are overloaded versions of the non-placement delete functions. The non-placement delete functions are declared as:
-
void operator delete (void *) throw;
void operator delete (void *) throw;
The Standard C++ library provides two placement overloads each for these functions. Their declarations are:
-
void operator delete (void *, const std::nothrow_t &) throw;
void operator delete (void *, void *) throw;
void operator delete (void *, const std::nothrow_t &) throw;
void operator delete (void *, void *) throw;
In all of the overloads, the first parameter to the operator delete
function is of type void *, which is the address of the storage to deallocate.
For both the new and the delete functions, the functions are global, are not in any namespace, and do not have static linkage.
Read more about this topic: Placement Syntax
Famous quotes containing the word functions:
“Those things which now most engage the attention of men, as politics and the daily routine, are, it is true, vital functions of human society, but should be unconsciously performed, like the corresponding functions of the physical body.”
—Henry David Thoreau (18171862)
“Adolescents, for all their self-involvement, are emerging from the self-centeredness of childhood. Their perception of other people has more depth. They are better equipped at appreciating others reasons for action, or the basis of others emotions. But this maturity functions in a piecemeal fashion. They show more understanding of their friends, but not of their teachers.”
—Terri Apter (20th century)
“Mark the babe
Not long accustomed to this breathing world;
One that hath barely learned to shape a smile,
Though yet irrational of soul, to grasp
With tiny fingerto let fall a tear;
And, as the heavy cloud of sleep dissolves,
To stretch his limbs, bemocking, as might seem,
The outward functions of intelligent man.”
—William Wordsworth (17701850)