what’s placement new operator and why do we need it.

In this article we will discuss what is placement new operator and what’s its need.

Need of placement new operator

Every when we create a new object using new operator, memory is allocated on heap i.e.

int * ptr = new int;

But there might be scenarios when we want to dynamically create an object at some specific memory location.
For example, in embedded devices or at shared memory etc.


In such scenario we don’t want new memory to be allocated on heap, but use a given memory address to create a new object.

[showads ad=inside_post]

To achieve this we use placement new operator,

Placement new operator

In placement new operator we pass memory address to new as a parameter, placement new operator will use this memory to create a new object. It also calls the constructor on it and then returns the same passed address.

Check out this example,

#include <iostream>
#include <new>
#include <cstdlib>

int main()
int * buffer = new int[1000];

// Will not allocate new memory on heap.
// Will use passed buffer to allocate the memory
int * ptr = new(buffer) int;
*ptr = 7;


delete [] buffer;
return 0;

We don’t need to delete the object created using placement new operator because no new memory was allocated for it. So, instead of calling delete operator on it, one can call the destructor explicitly if required.

Do you want to Learn Modern C++ from best?

We have curated a list of Best C++ Courses, that will teach you the cutting edge Modern C++ from the absolute beginning to advanced level. It will also introduce to you the word of Smart Pointers, Move semantics, Rvalue, Lambda function, auto, Variadic template, range based for loops, Multi-threading and many other latest features of C++ i.e. from C++11 to C++20.

Check Detailed Reviews of Best Modern C++ Courses

Remember, C++ requires a lot of patience, persistence, and practice. So, start learning today.

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top