MemoryInfo

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

MemoryInfo

04 Oct 2013, 08:02

MemoryInfo
Shows info about memory via AutoHotkey


Source
MemoryInfo.ahk (GitHub)


Example
Image
Image


References
- GlobalMemoryStatusEx function (msdn)
- SetProcessWorkingSetSize function (msdn)
- EmptyWorkingSet function (msdn)
- GetNumberFormat function (msdn)
- ITaskbarList3 interface (msdn)


Contributing
- thanks to AutoHotkey Community


Questions / Bugs / Issues
Please report any bugs or issues here. Same for any questions.


Copyright and License
The Unlicense
Last edited by jNizM on 16 Feb 2015, 02:48, edited 12 times in total.
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: MemoryInfo

04 Oct 2013, 12:43

[GlobalMemoryStatusEx function / MEMORYSTATUSEX structure] (Update 2015-02-16)

PSAPI Functions

Code: Select all

; ===============================================================================================================================
; Function......: GlobalMemoryStatusEx
; DLL...........: Kernel32.dll
; Library.......: Kernel32.lib
; U/ANSI........:
; Author........: jNizM
; Modified......:
; Links.........: https://msdn.microsoft.com/en-us/library/aa366589.aspx
;                 https://msdn.microsoft.com/en-us/library/windows/desktop/aa366589.aspx
; ===============================================================================================================================
GlobalMemoryStatusEx()
{
    static MEMORYSTATUSEX, init := VarSetCapacity(MEMORYSTATUSEX, 64, 0) && NumPut(64, MEMORYSTATUSEX, "UInt")
    if !(DllCall("kernel32.dll\GlobalMemoryStatusEx", "Ptr", &MEMORYSTATUSEX))
		return DllCall("kernel32.dll\GetLastError")
    return { 1 : NumGet(MEMORYSTATUSEX,  0, "UInt"),   2 : NumGet(MEMORYSTATUSEX,  4, "UInt")
           , 3 : NumGet(MEMORYSTATUSEX,  8, "UInt64"), 4 : NumGet(MEMORYSTATUSEX, 16, "UInt64")
           , 5 : NumGet(MEMORYSTATUSEX, 24, "UInt64"), 6 : NumGet(MEMORYSTATUSEX, 32, "UInt64")
           , 7 : NumGet(MEMORYSTATUSEX, 40, "UInt64"), 8 : NumGet(MEMORYSTATUSEX, 48, "UInt64")
           , 9 : NumGet(MEMORYSTATUSEX, 56, "UInt64") }
}
; ===============================================================================================================================

GlobalMemoryStatusEx := GlobalMemoryStatusEx()

MsgBox, % "GlobalMemoryStatusEx function`n"
        . "MEMORYSTATUSEX structure`n`n"
        . "Lenght:`t`t`t"                 GlobalMemoryStatusEx[1]   "`n`n"
        . "MemoryLoad:`t`t"               GlobalMemoryStatusEx[2]   " %`n`n"
        . "TotalPhys:`t`t`t"              GlobalMemoryStatusEx[3]   " bytes`n"
        . "AvailPhys:`t`t`t"              GlobalMemoryStatusEx[4]   " bytes`n`n"
        . "TotalPageFile:`t`t"            GlobalMemoryStatusEx[5]   " bytes`n"
        . "AvailPageFile:`t`t"            GlobalMemoryStatusEx[6]   " bytes`n`n"
        . "TotalVirtual:`t`t"             GlobalMemoryStatusEx[7]   " bytes`n"
        . "AvailVirtual:`t`t"             GlobalMemoryStatusEx[8]   " bytes`n`n"
        . "AvailExtendedVirtual:`t`t"     GlobalMemoryStatusEx[9]





/* C++ ==========================================================================================================================
BOOL WINAPI GlobalMemoryStatusEx(                                                    // UInt
    _Inout_  LPMEMORYSTATUSEX lpBuffer                                               // Ptr        (64)
);


typedef struct _MEMORYSTATUSEX {
    DWORD     dwLength;                                                              // UInt        4          =>   0
    DWORD     dwMemoryLoad;                                                          // UInt        4          =>   4
    DWORDLONG ullTotalPhys;                                                          // UInt64      8          =>   8
    DWORDLONG ullAvailPhys;                                                          // UInt64      8          =>  16
    DWORDLONG ullTotalPageFile;                                                      // UInt64      8          =>  24
    DWORDLONG ullAvailPageFile;                                                      // UInt64      8          =>  32
    DWORDLONG ullTotalVirtual;                                                       // UInt64      8          =>  40
    DWORDLONG ullAvailVirtual;                                                       // UInt64      8          =>  48
    DWORDLONG ullAvailExtendedVirtual;                                               // UInt64      8          =>  56
} MEMORYSTATUSEX, *LPMEMORYSTATUSEX;
============================================================================================================================== */
Last edited by jNizM on 16 Feb 2015, 07:49, edited 15 times in total.
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
User avatar
joedf
Posts: 8958
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: MemoryInfo

04 Oct 2013, 12:48

I like it! Nice GUI too! I have made something similar.. But I've never released it...
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: MemoryInfo

04 Oct 2013, 15:43

Nice GUI, nice avatar, and nice formats of the post. :D
User avatar
DataLife
Posts: 447
Joined: 29 Sep 2013, 19:52

Re: MemoryInfo

04 Oct 2013, 16:48

@jNizM

If I were to use only one of them, which do you recommend the WMI or DLL version?
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
User avatar
joedf
Posts: 8958
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: MemoryInfo

04 Oct 2013, 19:53

DataLife wrote:@jNizM
If I were to use only one of them, which do you recommend the WMI or DLL version?
System Calls (Dllcall) have way better performance than WMI, because WMI ("bloated") does the same but indirectly.
In fact, all programs do system calls. The fundementals of the operating system.;)
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
User avatar
JnLlnd
Posts: 487
Joined: 29 Sep 2013, 21:29
Location: Montreal, Quebec, Canada
Contact:

Re: MemoryInfo

05 Oct 2013, 10:04

I had the same question (which version to use under what circumstances?). Thanks for the script update and info.
:thumbup: Author of freeware Quick Access Popup, the powerful Windows folders, apps and documents launcher!
:P Now working on Quick Clipboard Editor
:ugeek: The Automator's Courses on AutoHotkey
Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

Re: MemoryInfo

06 Oct 2013, 04:27

what is clear memory function, and what does it do exactly when i press Clear Memory?
Alibaba
Posts: 480
Joined: 29 Sep 2013, 16:15
Location: Germany

Re: MemoryInfo

06 Oct 2013, 05:10

Guest10 wrote:what is clear memory function, and what does it do exactly when i press Clear Memory?
It clears memory, that isn't free yet, but not used anymore.
"Nothing is quieter than a loaded gun." - Heinrich Heine
Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

Re: MemoryInfo

07 Oct 2013, 08:21

when i run MemoryInfo v0.1. the bars show yellow color bars not green as showcased at the top of the page. is the color of bars any indication of the amount of memory available, etc. and could go from green to yellow depending on the amount of memory and ratios, etc. (as i suspect)?
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: MemoryInfo

07 Oct 2013, 08:23

yes...

Code: Select all

Used:
Green --> Yellow --> Orange --> Red
0-19% --> 20-39% --> 40-69% --> 70-100%

Free:
Red   --> Orange --> Yellow --> Green
0-30% --> 31-50% --> 51-80% --> 81-100%
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: MemoryInfo

08 Oct 2013, 01:58

Update: v0.2
- Memory in percent
- Only DLL-Version left
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: MemoryInfo

09 Oct 2013, 07:19

[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

Re: MemoryInfo

09 Oct 2013, 07:43

is this now the latest for the 2nd post script (AHK)?

Code: Select all

GlobalMemoryStatusEx(GMS = 1) {
    VarSetCapacity(MEMORYSTATUSEX, 64, 0)
    NumPut(64, MEMORYSTATUSEX)
    DllCall("GlobalMemoryStatusEx", "ptr", &MEMORYSTATUSEX)
    return, % (GMS = "0") ? NumGet(MEMORYSTATUSEX, 0, "Int")
            : (GMS = "1") ? NumGet(MEMORYSTATUSEX, 4, "Int")
            : (GMS = "2") ? Round((NumGet(MEMORYSTATUSEX,  8, "Int64") / 1024**2), 2)
            : (GMS = "3") ? Round((NumGet(MEMORYSTATUSEX, 16, "Int64") / 1024**2), 2)
            : (GMS = "4") ? Round((NumGet(MEMORYSTATUSEX, 24, "Int64") / 1024**2), 2)
            : (GMS = "5") ? Round((NumGet(MEMORYSTATUSEX, 32, "Int64") / 1024**2), 2)
            : (GMS = "6") ? Round((NumGet(MEMORYSTATUSEX, 40, "Int64") / 1024**2), 2)
            : (GMS = "7") ? Round((NumGet(MEMORYSTATUSEX, 48, "Int64") / 1024**2), 2)
            : (GMS = "8") ? NumGet(MEMORYSTATUSEX, 56, "Int")
            : "FAIL"
}

MsgBox, 48, GlobalMemoryStatusEx, % "GlobalMemoryStatusEx function /`n"
        . "MEMORYSTATUSEX structure`n`n"
        . "Lenght:`t`t`t"             GlobalMemoryStatusEx(0)  "`n`n"
        . "MemoryLoad:`t`t"           GlobalMemoryStatusEx(1)  " %`n`n"
        . "TotalPhys:`t`t`t"          GlobalMemoryStatusEx(2)  " MB`n"
        . "AvailPhys:`t`t`t"          GlobalMemoryStatusEx(3)  " MB`n`n"
        . "TotalPageFile:`t`t"        GlobalMemoryStatusEx(4)  " MB`n"
        . "AvailPageFile:`t`t"        GlobalMemoryStatusEx(5)  " MB`n`n"
        . "TotalVirtual:`t`t"         GlobalMemoryStatusEx(6)  " MB`n"
        . "AvailVirtual:`t`t"         GlobalMemoryStatusEx(7)  " MB`n`n"
        . "AvailExtendedVirtual:`t`t" GlobalMemoryStatusEx(8)  " MB`n"
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: MemoryInfo

09 Oct 2013, 08:12

I updated the whole 2nd post, so yes
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
mikek
Posts: 11
Joined: 30 Sep 2013, 17:17

Re: MemoryInfo

27 Dec 2013, 13:35

This is fantastic, jNizM. Thank you so much for sharing this. I plan to use your function to log memory usage on task machines and our server, and report when memory gets low.

- Mike
immorrr
Posts: 7
Joined: 07 Sep 2014, 21:23

Re: MemoryInfo v0.1

15 Feb 2015, 03:09

i love using the memory cleaning stuff but i have noticed that it sometimes bugs for me :(
It is not happening very often but if it happens the whole script (which makes use of this) crashs with the following errormsg:
errormsg
any ideas how to fix this?
User avatar
Soft
Posts: 174
Joined: 07 Jan 2015, 13:18
Location: Seoul
Contact:

Re: MemoryInfo v0.1

15 Feb 2015, 03:25

neat gui!
AutoHotkey & AutoHotkey_H v1.1.22.07
User avatar
boiler
Posts: 16949
Joined: 21 Dec 2014, 02:44

Re: MemoryInfo

15 Feb 2015, 07:58

jNizM wrote:

Code: Select all

Used:
Green --> Yellow --> Orange --> Red
0-19% --> 20-39% --> 40-69% --> 70-100%

Free:
Red   --> Orange --> Yellow --> Green
0-30% --> 31-50% --> 51-80% --> 81-100%
Mine is 55% free and 45% used, yet both bars are green. :?:
User avatar
boiler
Posts: 16949
Joined: 21 Dec 2014, 02:44

Re: MemoryInfo v0.1

15 Feb 2015, 08:11

Your code looks like it uses the same criteria for both bars. Perhaps a copy/paste and didn't finish editing? Also, it looks like there are no breaks below 70%.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 171 guests