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 are string library functions(syntax).

0 Answers   Accenture,


Mention the default functions in C++, how would you detect that error has occurred inside the constructor and destructor.

0 Answers   Adobe,


Write a program that can take input from 3 to 8 and calculate the average?

0 Answers   Accenture,


What are the fundamental features of an object-oriented language?

0 Answers   Accenture,


Write a C++ Program to Check Whether a character is Vowel or Consonant.

2 Answers  


Briefly explain various access specifiers in C++.

0 Answers   Amdocs,


There is a base class sub, with a member function fnsub(). There are two classes super1 and super2 which are sub classes of the base class sub.if and pointer object is created of the class sub which points to any of the two classes super1 and super2, if fnsub() is called which one will be inoked?

0 Answers   Alter,


what is friend function in C++?

0 Answers   TCS,


What is wrong with this statement? std::auto_ptr ptr(new char[10]);

0 Answers   Amazon,


How to convert integer to string in C++

0 Answers  


In C++ what do you mean by Inheritance?

0 Answers   Accenture,


How can a C function be called in a C++ program?

0 Answers  


Categories