我正在使用Delphi 2009进行编码,我想知道程序使用了多少内存.由于内存管理器在释放对象时不会将未使用的内存释放回操作系统,因此它可能会在内存中缓存以供下次使用.我的问题是,是否
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,因此您可能需要将NativeUInt更改为Int64.