-3

在一次采访中,有人问我

假设您有 25 MB 的内存,并且您有 3 个每个 10 MB 的进程。如何确保您的进程不会耗尽内存?

我回答说,如果我使用placement new它就会存活下来。他们问我和你placement new有什么关系realloc

我想知道placement new真的有关系realloc吗?

4

1 回答 1

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.

于 2013-10-07T04:47:22.743 回答