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).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…