|
INTERVIEW QUESTIONS
DATABASE
DATA STRUCTURE
DETAILS
Question: What is placement new?
Answer: 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.
|
|
|
Category |
Data Structure Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.2) By 9441 users |
Added on |
9/13/2014 |
Views |
70325 |
Rate it! |
|
|
Question:
What is placement new?
Answer:
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. Source: CoolInterview.com
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
|
Related Questions |
View Answer |
|
When can you tell that a memory leak will occur?
|
View Answer
|
|
What is a node class?
|
View Answer
|
|
Minimum number of queues needed to implement the priority queue?
|
View Answer
|
|
In an AVL tree, at what condition the balancing is to be done?
|
View Answer
|
|
What is the bucket size, when the overlapping and collision occur at same time?
|
View Answer
|
|
What is the easiest sorting method to use?
|
View Answer
|
|
What is the heap?
|
View Answer
|
|
How can I search for data in a linked list?
|
View Answer
|
|
What is the quickest sorting method to use?
|
View Answer
|
|
Whether Linked List is linear or Non-linear data structure?
|
View Answer
|
|
Does the minimum spanning tree of a graph give the shortest distance between any 2 specified nodes?
|
View Answer
|
|
What is a spanning Tree?
|
View Answer
|
|
In RDBMS, what is the efficient data structure used in the internal storage representation?
|
View Answer
|
|
List out few of the Application of tree data-structure?
|
View Answer
|
|
What are the methods available in storing sequential files ?
|
View Answer
|
|
What is the data structures used to perform recursion?
|
View Answer
|
|
If you are using C language to implement the heterogeneous linked list, what pointer type will you use?
|
View Answer
|
|
List out the areas in which data structures are applied extensively?
|
View Answer
|
|
Name the data structure used to maintain file identification?
|
View Answer
|
|
Which one is faster? A binary search of an orderd set of elements in an array or a sequential search of the elements.
|
View Answer
|