What is placement new?
Answer / ritesh pal
When you want to call a constructor directly, you use the placement new. Sometimes you have some raw memory that's already been allocated, and you need to construct an object in the memory you have. Operator new's special version placement new allows you to do it.
class Widget
{
public :
Widget(int widgetsize);
...
Widget* Construct_widget_int_buffer(void *buffer,int widgetsize)
{
return new(buffer) Widget(widgetsize);
}
};
This function returns a pointer to a Widget object that's constructed within the buffer passed to the function. Such a function might be useful for applications using shared memory or memory-mapped I/O, because objects in such applications must be placed at specific addresses or in memory allocated by special routines.
| Is This Answer Correct ? | 0 Yes | 0 No |
What is the difference between member functions and static member functions?
What Is Polymorphism in C++ ?
2 Answers IBS, Impetus, ITC Indian Tobacco Company, Motorola,
How will you execute a stack using a priority queue? (Push and pop should be in O (1)).
What are the advantages/disadvantages of using #define?
What is the 4 difference between delete[] and delete?
When must you use a constructor initializer list?
What is conversion constructor in C++
How to convert integer to string in C++
Without using third variable write a code to swap two numbers.
Do you know about Agilent PRECOMPILERS. ?
Consider the following C++ program
What is a virtual function in C++?