Placement Syntax - Functions

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:

    “In today’s world parents find themselves at the mercy of a society which imposes pressures and priorities that allow neither time nor place for meaningful activities and relations between children and adults, which downgrade the role of parents and the functions of parenthood, and which prevent the parent from doing things he wants to do as a guide, friend, and companion to his children.”
    —Urie Bronfenbrenner (b. 1917)

    “The English masses are lovable: they are kind, decent, tolerant, practical and not stupid. The tragedy is that there are too many of them, and that they are aimless, having outgrown the servile functions for which they were encouraged to multiply. One day these huge crowds will have to seize power because there will be nothing else for them to do, and yet they neither demand power nor are ready to make use of it; they will learn only to be bored in a new way.”
    —Cyril Connolly (1903–1974)

    “One of the most highly valued functions of used parents these days is to be the villains of their children’s lives, the people the child blames for any shortcomings or disappointments. But if your identity comes from your parents’ failings, then you remain forever a member of the child generation, stuck and unable to move on to an adulthood in which you identify yourself in terms of what you do, not what has been done to you.”
    —Frank Pittman (20th century)