Placement syntax: Difference between revisions

Content deleted Content added
No edit summary
Vskid1008 (talk | contribs)
Line 72:
* You want to create objects in memory shared between two different processes.
* You want objects to be created in non-pageable memory.
* You want to separate memory allocation from construction e.g. in implementing a <code>std::vector<></code> (see <code>std::vector<>::reserve</code>).
 
The basic problem is that the constructor is a peculiar function; when it starts off, there is no object, only raw memory. And by the time it finishes, you have a fully initialized object. Therefore, i) The constructor cannot be called on an object ii) However, it needs to access (and initialize) non-static members. This makes calling the constructor directly an error. The solution is the placement form of operator new.