I have a routine that, in debug mode, calls the FastMM function to use memory (as David suggested). When FastMM is not installed, that is, in my release mode, I use the following code, which requires only a reference to the Delphi system unit:
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;
I am using XE2, so you may need to change NativeUInt to Int64.
source share