Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


What is placement new?



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

Post New Answer

More C++ Interview Questions

What is RTTI and why do you need it?

0 Answers   Amazon,


Implement a 2D bit-matrix representing monochrome pixels which will have only OFF/ON values and will take on an average only one bit of memory for each stored bit. How to perform various operations on it?

0 Answers   Adobe,


Write a C++ Program to Find Sum and Average of three numbers.

1 Answers  


What is the difference between public, private, and protected inheritance?

0 Answers   Amazon,


Without using third variable write a code to swap two numbers.

0 Answers   Accenture,


What does it mean to declare a member function as static in C++?

0 Answers   Amazon,


How will you print a list of all unique words from a string which may contain repeated words?

0 Answers   Adobe,


How do you write a function that can reverse a linked-list in C++?

0 Answers   IBS,


Write a program to input an integer from the keyboard and display on the screen “WELL DONE” that many times.

1 Answers  


How do you work around them?

0 Answers   Amazon,


What is placement new?

1 Answers   Amazon,


What is conversion constructor in C++

0 Answers   TCS,


Categories