Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
454 views
in Technique[技术] by (71.8m points)

memory management - C++, Free-Store vs Heap

Dynamic allocations with new/delete are said to take place on the free-store,
while malloc/free operations use the heap.

I'd like to know if there is an actual difference, in practice.
Do compilers make a distinction between the two terms? (Free store and Heap, not new/malloc)

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

For C++, the difference between the free store and the heap has become purely conceptual. Like a jar for collecting bugs, and one for collecting cookies. One is labeled one way, the other another. This designation is meant to drive home the point that you NEVER mix "new" and "delete" with "malloc", "realloc", or "free" (or bit level sets for that matter).

During interviews it's good to say that "new and delete use the free store, malloc and free use the heap; new and delete call the constructor and destructor, respectively, however malloc and free do not." Yet, you will often hear that the memory segments are really in the same area - however, that CAN be compiler specific, that is to say, it is possible that both can designate different memory spaces as pools (not sure why it would be, though).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...