Why does _get_heap_handle equal to GetProcessHeap?

前端 未结 4 1389
清歌不尽
清歌不尽 2020-12-20 06:21

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

4条回答
  •  伪装坚强ぢ
    2020-12-20 07:06

    FWIW, in addition to Hans's answer. I've managed to force VS2012 CRT to use private heap with below options (unfortunately with linker warnings):

    1. Switch to /MT in C/C++/Code Generation/Runtime Library (i.e. to use static c-runtime linking)
    2. Add smalheap.obj to Linker/Input/Additional Dependencies
    3. Add /FORCE:MULTIPLE to Linker/Command Line/Additional Options (to avoid LNK2005 error for _heap_init and friends)

    IMHO, it's sad that we do not have an option for private heap and c-runtime dynamic dll. This would help with memory leaks in 3rd party libraries. In case of long running process you can just unload everything and load again.

提交回复
热议问题