AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Function similar to AutoIt's MemGetStats

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List
View previous topic :: View next topic  
Author Message
Cerdan



Joined: 04 Oct 2005
Posts: 11

PostPosted: Wed Nov 02, 2005 11:08 am    Post subject: Function similar to AutoIt's MemGetStats Reply with quote

Hi there,

such a function would be very nice to have as I want to read the real memory size out of my system:

http://www.autoitscript.com/autoit3/docs/functions/MemGetStats.htm

Maybe this is for help for the programmers of AutoHotkey:

http://vb-tec.de/memstat.htm

(OK, it's just VB, but it is an example how to use the C-API calls to get the stuff).

Greetings, Thomas
Back to top
View user's profile Send private message
antonyb



Joined: 26 May 2004
Posts: 61

PostPosted: Wed Nov 02, 2005 12:48 pm    Post subject: Reply with quote

With thanks to Shimanov and his ReadInteger function!

Code:
statString:=MemGetStats()
StringSplit, stats, statString, |

FileAppend, Memory Load: %stats1%`n, *
FileAppend, Total Physical Ram: %stats2%k`n, *
FileAppend, Available Physical Ram: %stats3%k`n, *
FileAppend, Total Pagefile: %stats4%k`n, *
FileAppend, Available Pagefile: %stats5%k`n, *
FileAppend, Total Virtual: %stats6%k`n, *
FileAppend, Available Virtual: %stats7%k`n, *

MemGetStats()
{
  ; See:
  ; http://msdn.microsoft.com/library/default.asp?url=/library/en-us/memory/base/memorystatus_str.asp

  VarSetCapacity(memorystatus, 4+4+4+4+4+4+4+4)
  success := DllCall("kernel32.dll\GlobalMemoryStatus", "uint", &memorystatus)
  stats := ReadInteger(&memorystatus,4,4, false)                          ; Memory Load (Percentage of memory in use)
  stats := stats "|" Round(ReadInteger(&memorystatus,8,4, false)/1024)    ; Total Physical Ram
  stats := stats "|" Round(ReadInteger(&memorystatus,12,4, false)/1024)   ; Available Physical Ram
  stats := stats "|" Round(ReadInteger(&memorystatus,16,4, false)/1024)   ; Total Pagefile
  stats := stats "|" Round(ReadInteger(&memorystatus,20,4, false)/1024)   ; Available Pagefile
  stats := stats "|" Round(ReadInteger(&memorystatus,24,4, false)/1024)   ; Total Virtual
  stats := stats "|" Round(ReadInteger(&memorystatus,28,4, false)/1024)   ; Available Virtual
  return stats
}

ReadInteger( p_address, p_offset, p_size, p_hex=true )
{
  value = 0
  old_FormatInteger := a_FormatInteger
  if ( p_hex )
    SetFormat, integer, hex
  else
    SetFormat, integer, dec
  loop, %p_size%
    value := value+( *( ( p_address+p_offset )+( a_Index-1 ) ) << ( 8* ( a_Index-1 ) ) )
  SetFormat, integer, %old_FormatInteger%
  return, value
}


Ant
Back to top
View user's profile Send private message
shimanov



Joined: 25 Sep 2005
Posts: 612

PostPosted: Wed Nov 02, 2005 12:56 pm    Post subject: Reply with quote

antonyb wrote:
With thanks to Shimanov and his ReadInteger function!


Cool!

If I were just a bit faster, I would have posted exactly (nearly so) the same code.

Oh well.
Back to top
View user's profile Send private message
antonyb



Joined: 26 May 2004
Posts: 61

PostPosted: Wed Nov 02, 2005 1:02 pm    Post subject: Reply with quote

Hah! Beat you to it!

I tried playing around with the NT performance counters too (here) but got nowhere fast. So if you get bored.... Smile

Ant.
Back to top
View user's profile Send private message
Cerdan



Joined: 04 Oct 2005
Posts: 11

PostPosted: Wed Nov 02, 2005 1:23 pm    Post subject: Reply with quote

Ah, thank you very much, this was really fast Wink

Greetings, Thomas
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group