Is it possible in C++ to create a new object at a specific memory location? I have a block of shared memory in which I would like to create an object. Is this possible?
You want placement new(). It basically calls the constructor using a block of existing memory instead of allocating new memory from the heap.
new
Edit: make sure that you understand the note about being responsible for calling the destructor explicitly for objects created using placement new() before you use it!
new()
2.1m questions
2.1m answers
60 comments
57.0k users