C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[71388] Re:자신이 차지하는 메모리 용량 알고싶어요..
송신영 [palindrome] 3918 읽음    2014-06-02 13:39
MSDN 참고.

GetProcessMemoryInfo()

http://msdn.microsoft.com/en-us/library/windows/desktop/ms683219(v=vs.85).aspx

#pragma hdrstop

#include 
//---------------------------------------------------------------------------

#include 
#include 
#include 
#include 

#pragma argsused

#pragma link "Psapi.lib"

// To ensure correct resolution of symbols, add Psapi.lib to TARGETLIBS
// and compile with -DPSAPI_VERSION=1

void PrintMemoryInfo( DWORD processID )
{
    HANDLE hProcess;
    PROCESS_MEMORY_COUNTERS pmc;

    // Print the process identifier.

    printf( "\nProcess ID: %u\n", processID );

    // Print information about the memory usage of the process.

    hProcess = OpenProcess(  PROCESS_QUERY_INFORMATION |
                                    PROCESS_VM_READ,
                                    FALSE, processID );
    if (NULL == hProcess)
        return;

    if ( GetProcessMemoryInfo( hProcess, &pmc, sizeof(pmc)) )
    {
        printf( "\tPageFaultCount: 0x%08X\n", pmc.PageFaultCount );
        printf( "\tPeakWorkingSetSize: 0x%08X\n",
                  pmc.PeakWorkingSetSize );
        printf( "\tWorkingSetSize: 0x%08X\n", pmc.WorkingSetSize );
        printf( "\tQuotaPeakPagedPoolUsage: 0x%08X\n",
                  pmc.QuotaPeakPagedPoolUsage );
        printf( "\tQuotaPagedPoolUsage: 0x%08X\n",
                  pmc.QuotaPagedPoolUsage );
        printf( "\tQuotaPeakNonPagedPoolUsage: 0x%08X\n",
                  pmc.QuotaPeakNonPagedPoolUsage );
        printf( "\tQuotaNonPagedPoolUsage: 0x%08X\n",
                  pmc.QuotaNonPagedPoolUsage );
        printf( "\tPagefileUsage: 0x%08X\n", pmc.PagefileUsage );
        printf( "\tPeakPagefileUsage: 0x%08X\n",
                  pmc.PeakPagefileUsage );
    }

    CloseHandle( hProcess );
}



int _tmain(int argc, _TCHAR* argv[])
{
    // Get the list of process identifiers.

    DWORD aProcesses[1024], cbNeeded, cProcesses;
    unsigned int i;

    if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
    {
        return 1;
    }

    // Calculate how many process identifiers were returned.

    cProcesses = cbNeeded / sizeof(DWORD);

    // Print the memory usage for each process

    for ( i = 0; i < cProcesses; i++ )
    {
        PrintMemoryInfo( aProcesses[i] );
    }

    // 자신의 Process ID
    DWORD PID = GetCurrentProcessId();
    printf("GetCurrentProcessId = %d\r\n",PID);

    getch();

    return 0;
}
//---------------------------------------------------------------------------



locke 님이 쓰신 글 :
: 작업관리자 보면.. 각 프로세스마다 메모리 차지하고 있는 내용이 보이잖아요.
:
: 제가 띄운 프로그램이 차지하고 있는 전체 메모리를 수치로 알고싶습니다.
:
: 관련 api가 있을거 같은데.. 아시분 도와주세요.
:
: -locke
:

+ -

관련 글 리스트
71386 자신이 차지하는 메모리 용량 알고싶어요.. locke 3264 2014/05/31
71388     Re:자신이 차지하는 메모리 용량 알고싶어요.. 송신영 3918 2014/06/02
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.