Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

According to this article, CRT uses separate heap (is it private heap?), but this little example shows that CRT heap and Default heap are the same:

HANDLE heaps[64];
DWORD heapCount = GetProcessHeaps(64, heaps);    
for (int i = 0; i<heapCount; i++)
    printf("heap %d : [0x%x]
", i, heaps[i]);
printf("crt heap[0x%x], default heap[0x%x]
", _get_heap_handle(), GetProcessHeap());

In what cases GetProcessHeap and _get_heap_handle return different handles?

// Compiled with VS2012 (Platform toolset v110)

See Question&Answers more detail:os

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

1 Answer

This is new for VS2012, the CRT now uses the default process heap to allocate from. Previous versions have always created their own heap.

A significant advantage of using the default heap is that interop with code in a DLL will be a lot easier, it can significantly reduce the trouble of having to use a DLL that has its own copy of the CRT linked-in. Assuming that copy is also 2012+ vintage of course.

A potential disadvantage is that it is more difficult to generate a meaningful diagnostic or cleanly shutdown when the process heap becomes corrupted, Windows also uses that heap. And memory corruption in your code can destabilize OS calls, the kind that doesn't involve kernel calls, anything is possible there. I can imagine a security risk as well, I assume that this choice was made once they felt comfortable with the secure CRT enhancements.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...