1

What are the placement and non-placement allocation/deallocation function? I've been reading sec. 3.7.4.2 of N3797 and come across with the placement and non-placement allocation/deallocation function concepts. For instance:

The global operator delete with exactly one parameter is a usual (non-placement) deallocation function.

I could not find a definition of these concepts and I assume that non-placement is the functions which have one of the following signature:

void* operator new(std::size_t);
void* operator new[](std::size_t);
void operator delete(void*);
void operator delete[](void*);
void operator delete(void*, std::size_t) noexcept;
void operator delete[](void*, std::size_t) noexcept;

Have I understood correctly?

  • 1
    They let you construct object on already allocated memory. vector uses it. – Neil Kirk Jul 24 '14 at 13:28
  • possible duplicate of [What uses are there for "placement new"?](http://stackoverflow.com/questions/222557/what-uses-are-there-for-placement-new) – Neil Kirk Jul 24 '14 at 13:29
  • @NeilKirk Why do you think so? That is, could you provide a reference to the Standard? –  Jul 24 '14 at 13:29
  • No. I don't know if it's mandatory to do it that way, but I know many implementations do. – Neil Kirk Jul 24 '14 at 13:29
  • @Niall Yes, that is exactly what I looked for. Thank you. –  Jul 24 '14 at 13:39
  • I think the definition for *placement deallocation function* is in 3.7.4.2/2, which describes *deallocation functions* and which of those are *non-placement deallocation functions*. I think you can conclude that those *deallocation functions* which are not *non-placement deallocation functions* then are *placement deallocation functions*. – dyp Jul 24 '14 at 13:45
  • @Niall 18.6.1.3 describes the Standard Library's default implementation for some placement (de)allocation functions. It does not define what a placement (de)allocation function is. – dyp Jul 24 '14 at 13:48
  • @DmitryFucintv, my typo.. 18.6.1.3 (n3797) is "Placement forms"... – Niall Jul 24 '14 at 13:48
  • See also the sample code I posted [in this other question on the same section](http://stackoverflow.com/questions/24908550/deallocation-function-precludes-use-of-an-allocation-with-two-parameter). – Khouri Giordano Jul 24 '14 at 13:51
  • @dyp That is, have we already defined placement new and delete form in the standard library? –  Jul 24 '14 at 13:55
  • The Standard Library provides default versions for *some* placement allocation and placement deallocation functions. The "placement" is misleading, it just means that there might be additional parameters. So there's not *a single* placement form. – dyp Jul 24 '14 at 13:59
  • possible duplicate of [Operator delete signature unexpected behavior](http://stackoverflow.com/questions/24770119/operator-delete-signature-unexpected-behavior) – Deduplicator Jul 24 '14 at 14:03

1 Answers1

-1

The definition of placement new is in N3797 in section 5.3.4.13:

The new-placement syntax is used to supply additional arguments to an allocation function. If used, overload resolution is performed on a function call created by assembling an argument list consisting of the amount of space requested (the first argument) and the expressions in the new-placement part of the new-expression (the second and succeeding arguments). The first of these arguments has type std::size_t and the remaining arguments have the corresponding types of the expressions in the new-placement.

Kiroxas
  • 881
  • 10
  • 24
Wojtek Surowka
  • 19,646
  • 4
  • 44
  • 49
  • 1
    A *new-expression* is not an allocation function. Those concepts are linked, but not identical. – dyp Jul 24 '14 at 13:43