“Private Bytes” doesn't reflect it. How to find exact memory allocated by process?

前端 未结 1 1975
挽巷
挽巷 2021-01-15 19:00

Here is sample piece of C++ code compiled and run using VS2010 on Windows XP.

It prints \"private bytes\" before and after allocation.

void PrintPri         


        
相关标签:
1条回答
  • 2021-01-15 19:27

    Your solution of checking the private bytes is correct, only your assumption about _heapmin is wrong.

    _heapmin does not work as documented. _heapmin is documented as "Releases unused heap memory to the operating system."

    The implementation (see "\Program Files (x86)\Microsoft Visual Studio 10.0\VC\crt\src\heapmin.c") is

    int __cdecl _heapmin(void)
    {
            if ( HeapCompact( _crtheap, 0 ) == 0 ) {
                return -1;
            }
            else {
                return 0;
            }
    }
    

    HeapCompact is documented to normally do quite nothing despite returning the size of the largest free block in the heap. It only does some extra stuff if a special global (debug purpose) flag is used.

    0 讨论(0)
提交回复
热议问题