-3

In one interview I was asked that

Suppose you have 25 MB of memory and you have three processes of 10 MB each. How to assure that your process should not run out of memory ?

I replied that if I use placement new it will survive. They asked me how you relate placement new to realloc?

I want to know is placement new really related to realloc?

user2845185
  • 79
  • 1
  • 1
  • 8
  • -1: please read wikipage on [placement new](http://en.wikipedia.org/wiki/Placement_syntax) – Basile Starynkevitch Oct 07 '13 at 04:43
  • The interview question was not a C++ question, but an operating systems question. You gave a C++ answer, so the interviewer probably was wondering if you understood what placement new was for, so you got a curve ball for a follow-up question. – jxh Oct 07 '13 at 04:52
  • Why do you want to delete your profile? At this point you're completely anonymous, and there's nothing embarrassing about your question. – Mark Ransom Oct 07 '13 at 05:07
  • @user2845185: Random people cannot delete other people's profile, that would not work. Besides, the profile just lists only this question, and this question would remain anyway. (And the previous comment tells more about you than your profile, "do the needful" is Indian English) – MSalters Oct 07 '13 at 08:28
  • You were clearly being interviewed by a version of the Eliza program. The correct response is, "how in the world will placement new save the situation?" – Kaz Jun 07 '14 at 00:41

1 Answers1

1

realloc isn't really valid with placement new. Since the memory might end up in a new location, any pointers referring to the object will become invalidated, especially the pointers contained within the objects themselves. Think of a linked list for example.

The interviewer was probably looking for a mention of virtual memory.

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622