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 kind of problems does name mangling cause?
What is a constructor initializer list?
dynamic scoping is
Explain why C++ is not purely Object Oriented Language
What are the advantages and disadvantages of B-star trees over Binary trees?
What is RTTI and why do you need it?
What is placement new?
What do you know about Volatile keyword in C++? Explain with an example code.
Write a program to read the values a, b and c and display x, where x=a/b–c. Test the program for the following values: (a) a = 250, b = 85, c = 25 (b) a = 300, b = 70, c = 70
If class D is derived from a base class B
What is data abstraction? How is it implemented in C++?
what do you mean by exception handling in C++?