2012-03-09 3 views
4

저는 Delphi 2009로 코딩 중이므로, 프로그램에서 사용한 메모리 양을 알고 싶습니다. 객체가 해제 될 때 메모리 관리자가 사용되지 않는 메모리를 OS로 다시 릴리스하지 않으므로 다음 사용을 위해 메모리 관리에 캐시 할 수 있습니다. 내 질문은 프로그램이 얼마나 많은 메모리를 사용했는지 알 수있는 방법이 있는지의 여부입니다. 메모리 관리자에 캐시 된 메모리는 제외해야합니다. 감사.메모리 사용량을 측정하는 방법

+1

올바르게 기억한다면 FastMM 정식 버전에는 데모 메모리 사용량 추적 프로그램이 포함되어 있습니다. 그게 당신이 필요로하는 것처럼 들리 네요. –

+2

이 주제에 대해 이미 몇 가지 질문이 있다고 생각합니다. 예를 보려면 http://stackoverflow.com/questions/4448129/why-doesnt-my-programs-memory-usage-return-to-normal-after-i-free-memory 또는 http://stackoverflow.com/questions를 참조하십시오./4475592/메모리 관리자에서 메모리 관리자로 전환하는 방법 - 사용하지 않는 메모리 – jpfollenius

+0

http://stackoverflow.com/questions/4448129/why-doesnt-my에서 누군가가 "Inside - Windows"값을 말할 수 있습니까? -programs-memory-usage-i-free-after-after-free-memory 질문에 대한 답변 – Branko

답변

1

저는 디버그 모드에서 FastMM 함수를 호출하여 메모리 사용을 얻는 루틴을 가지고 있습니다 (David의 제안대로). 당신이 INT64에 NativeUInt을 변경해야 할 수도 있으므로

function GetAllocatedMemoryBytes_NativeMemoryManager : NativeUInt; 
// Get the size of all allocations from the memory manager 
var 
    MemoryManagerState: TMemoryManagerState; 
    SmallBlockState: TSmallBlockTypeState; 
    i: Integer; 
begin 
    GetMemoryManagerState(MemoryManagerState); 
    Result := 0; 
    for i := low(MemoryManagerState.SmallBlockTypeStates) to 
     high(MemoryManagerState.SmallBlockTypeStates) do 
    begin 
    SmallBlockState := MemoryManagerState.SmallBlockTypeStates[i]; 
    Inc(Result, 
    SmallBlockState.AllocatedBlockCount*SmallBlockState.UseableBlockSize); 
    end; 

    Inc(Result, MemoryManagerState.TotalAllocatedMediumBlockSize); 
    Inc(Result, MemoryManagerState.TotalAllocatedLargeBlockSize); 
end; 

내가 XE2를 사용 FASTMM이 내 릴리스 모드에서 즉, 설치되어 있지 않은 경우 난 단지 델파이의 시스템 장치에 대한 참조를 필요로하는 다음 코드를 사용합니다.

+0

델파이 2009에는 NativeInt가 존재하지만 2GB 이상의 메모리를 할당하는 32 비트 프로세스에서는 NativeUInt가 될 것으로 기대합니다. –

관련 문제