Sadly, I can't get this working on Linux or MacOS, since I don't know much about the APIs of that systems, however, since you asked about the Task-Manager, I assume that a Win32 only solution would be enough. Note that this code needs the Psapi.dll, I don't know whether this is always included into the system, but at least every XP Home and Pro should have this, since (I guess) the Task-Mamager uses the same dll:
Strict
Framework brl.blitz
Local Lib = LoadLibraryW ( "Psapi.dll".ToWString ( ) )
If Not Lib
WriteStdout "Psapi.dll is missing, make sure that you've got a valid Windows XP installation~n"
Return
EndIf
Global GetProcessMemoryInfo ( Process , MemCounters:Byte Ptr , Size ) = GetProcAddress ( Lib , "GetProcessMemoryInfo".ToCString ( ) )
If Not GetProcessMemoryInfo
WriteStdout "Strange, couldn't find the GetProcessMemoryInfo function...~n"
Return
EndIf
Local PMC:TProcessMemoryCounters = New TProcessMemoryCounters
PMC.Size = SizeOf TProcessMemoryCounters
Local N = GetProcessMemoryInfo ( GetCurrentProcess ( ) , PMC , SizeOf TProcessMemoryCounters )
If Not N
WriteStdout "There was an error when calling the function...~n"
Return
EndIf
N = PMC.WorkingSetSize
WriteStdout "This process takes " + N + " bytes in memory.~n"
WriteStdout "The taskmamager shows this size probably as " + N / 1024 + "K.~n"
Type TProcessMemoryCounters
Field Size
Field PageFaultCounter
Field PeakWorkingSetSize
Field WorkingSetSize
Field QuotaPeakPagedPoolUsage
Field QuotaPagedPoolUsage
Field QuotaPeakNonPagedPoolUsage
Field QuotaNonPagedPoolUsage
Field PagefileUsage
Field PeakPagefileUsage
EndType
Extern "Win32"
Function GetCurrentProcess ( )
Function LoadLibraryW ( Name:Short Ptr )
Function GetProcAddress:Byte Ptr ( Lib , Name:Byte Ptr )
' Function GetProcessMemoryInfo ( Process , MemCounters:Byte Ptr , Size ) 'Doesn't work, seems like BlitzMax doesn't
'directly link to Psapi.dll (a bug?)
EndExternP.S.: I assumed you wanted to get this information about the process where you called the function. If not you need first to create a handle to the process, which you want to get the information about. To get this handle you need either
- the process id
- a handle to a thread which belongs to the process
- an id of such a thread
- a handle to a window created such a thread
- (not secure) the caption of such a window
But as long as you just need this information for the current process, the code above should work.