Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/152.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
&引用;“专用字节”;不';我没有反映出来。如何找到进程分配的确切内存? 这里是用VS2010在Windows XP上编译并运行的C++代码样件。p>_C++_Windows_Memory_Memory Management - Fatal编程技术网

&引用;“专用字节”;不';我没有反映出来。如何找到进程分配的确切内存? 这里是用VS2010在Windows XP上编译并运行的C++代码样件。p>

&引用;“专用字节”;不';我没有反映出来。如何找到进程分配的确切内存? 这里是用VS2010在Windows XP上编译并运行的C++代码样件。p>,c++,windows,memory,memory-management,C++,Windows,Memory,Memory Management,它在分配前后打印“专用字节” void PrintPrivateBytes() { HANDLE current_process; PROCESS_MEMORY_COUNTERS_EX pmc; current_process = GetCurrentProcess(); if (!GetProcessMemoryInfo(current_process, (PPROCESS_MEMORY_COUNTERS)&pmc, sizeof(pmc)))

它在分配前后打印“专用字节”

void PrintPrivateBytes()
{
    HANDLE current_process;
    PROCESS_MEMORY_COUNTERS_EX pmc;

    current_process = GetCurrentProcess();

    if (!GetProcessMemoryInfo(current_process, (PPROCESS_MEMORY_COUNTERS)&pmc, sizeof(pmc)))
    {
        std::cout << "\nGetProcessMemoryInfo failed" ;
        return;
    }

    std::cout << "\nProcess private bytes: " << pmc.PrivateUsage/1024 << " KB"; 
}

int _tmain(int argc, _TCHAR* argv[])
{
    // Code demonstrating private bytes doesn't change
    std::cout << "\n\nBefore allocating memory" ;
    PrintPrivateBytes();

    char* charptr = new char[8192];
    std::cout << "\n\nAfter allocating 8 KB memory" ;
    PrintPrivateBytes();

    delete[] charptr;
    std::cout << "\n\nAfter deleting memory" ;
    PrintPrivateBytes();

    int RetVal = _heapmin();
    std::cout << "\n\nAfter calling _heapmin" ;
    PrintPrivateBytes();

    return 0;
}
void PrintPrivateBytes()
{
处理当前的流程;
进程\内存\计数器\ pmc;
当前进程=GetCurrentProcess();
if(!GetProcessMemoryInfo(当前进程,(进程内存计数器)和pmc,sizeof(pmc)))
{

std::cout您检查私有字节的解决方案是正确的,只是您关于_heapmin的假设是错误的

_heapmin不能像文档中描述的那样工作。_heapmin是“将未使用的堆内存释放到操作系统。”

实现(请参见“\Program Files(x86)\Microsoft Visual Studio 10.0\VC\crt\src\heapmin.c”)是


HeapCompact通常不做任何事情,尽管返回堆中最大空闲块的大小。它只在特殊全局(调试目的)的情况下做一些额外的事情使用标志。

什么是_heapmin的返回值?@Werner:它返回0您不应该期望进程中释放的内存立即返回到操作系统。您看到的行为是正常的。假设您谈论的是提交的内存总量,您可以使用计算得出。另外请注意,Visual Studio C的源代码运行时可用,因此您可以检查\u heapmin是如何实现的。我知道了。但问题是如何找到进程获取的确切内存?如果没有办法,很难说进程是否存在内存泄漏。@Andrew我的意思是:您读取私有字节的解决方案不一定因为obser而出错梵蒂冈:是的。@Andrew _heapwalk等人。请注意,这不是你问的问题;运行时是进程的一部分,因此它的堆是“进程获取的内存”,即使它不是“代码获取的内存”。
int __cdecl _heapmin(void)
{
        if ( HeapCompact( _crtheap, 0 ) == 0 ) {
            return -1;
        }
        else {
            return 0;
        }
}