News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Memory Status Toy, Memstat.exe

Started by hutch--, June 26, 2019, 05:29:09 AM

Previous topic - Next topic

hutch--

Working with very large files (gigabytes) generates an unusual problem, the lazy write characteristic means there is less memory available while it is occurring. This tool uses a fast update method of polling the available memory and displaying it in close enough to real time. On testing in task manager it uses so little processor time that it does not register and remains at 0.

At 6.5k, it will not wear your hard disk out.  :winking: It is only bloated this far due to the manifest and version control block.

There is a later version posted below in this topic.

LiaoMi

Hi hutch,

what a very useful program, I have 32 gigabytes of memory, and I always have so many active documents and other running software, sometimes i forget that there is a limit of memory, it's usually too late at this moment, as some programs start to slow down and close with an error, with the message that they do not have enough memory.  :biggrin: With such a program, I do not need to go into the task manager!  :greenclp:  :thumbsup:

hutch--

#2
I have done a mod on the original to make it more flexible, by detecting if the app has the focus or not, the priority and poll duration is changed so it faster when it has the focus and goes into low priority mode with a slower polling rate when it does not have the focus. The duration difference is 100 ms when it has the focus (10 samples per second) and 500 ms when it has not (2 sample per second).

If you have a need for pesky little critters like this without choking your computer with too much overhead, techniques like this are useful in keeping the overhead down.

This is the additional code to do this.

      .case WM_ACTIVATE
      ; -------------------------------------------------------
      ; change delay and priority depending on activation state
      ; -------------------------------------------------------
        .switch wParam
          .case 0                                           ; 0 = WA_INACTIVE
            LowPriority
            mov delay, 500
            rcall SendMessage,hStat,SB_SETTEXT,0," Low Priority Mode"
          .case 1                                           ; 1 = WA_ACTIVE
            NormalPriority
            mov delay, 100
            rcall SendMessage,hStat,SB_SETTEXT,0," Startup Normal Priority"
          .case 2                                           ; 2 = WA_CLICKACTIVE
            NormalPriority
            mov delay, 100
            rcall SendMessage,hStat,SB_SETTEXT,0," Normal Priority Mode"
        .endsw


Get the one below.

LiaoMi

Quote from: hutch-- on June 27, 2019, 02:13:42 PM
I have done a mod on the original to make it more flexible, by detecting if the app has the focus or not, the priority and poll duration is changed so it faster when it has the focus and goes into low priority mode with a slower polling rate when it does not have the focus. The duration difference is 100 ms when it has the focus (10 samples per second) and 500 ms when it has not (2 sample per second).

If you have a need for pesky little critters like this without choking your computer with too much overhead, techniques like this are useful in keeping the overhead down.

This is the additional code to do this.

      .case WM_ACTIVATE
      ; -------------------------------------------------------
      ; change delay and priority depending on activation state
      ; -------------------------------------------------------
        .switch wParam
          .case 0                                           ; 0 = WA_INACTIVE
            LowPriority
            mov delay, 500
            rcall SendMessage,hStat,SB_SETTEXT,0," Low Priority Mode"
          .case 1                                           ; 1 = WA_ACTIVE
            NormalPriority
            mov delay, 100
            rcall SendMessage,hStat,SB_SETTEXT,0," Startup Normal Priority"
          .case 2                                           ; 2 = WA_CLICKACTIVE
            NormalPriority
            mov delay, 100
            rcall SendMessage,hStat,SB_SETTEXT,0," Normal Priority Mode"
        .endsw


The last digits can be used as a random number generator  :biggrin:  :thumbsup:

aw27

I am needing something like this as a Tray Icon  :icon_idea:

hutch--

I think you can set that in Win10. I used to know how to do it in XP but that is some years ago.

aw27

Quote from: hutch-- on June 29, 2019, 09:12:54 AM
I think you can set that in Win10. I used to know how to do it in XP but that is some years ago.
I am sure they have invented some UWP wrapper for the old way people used to do it.

https://www.codeproject.com/Articles/74/Adding-Icons-to-the-System-Tray
But I think there are posts in this forum about that.

hutch--

This should do the job, I added a minimise button and when it is minimised it displays the status on the task bar. I had a look at the tray icon but it was a lot of messing around and the display was not that good.

jj2007

It builds "out of the box", but the behaviour is a bit ambiguous. Left-click does nothing, right-click shows a menu. When exiting, the icon is still in the tray and disappears only when you hover over it. I see that with other (non-Masm) applications, too.

LiaoMi

Quote from: jj2007 on June 30, 2019, 07:04:56 AM
It builds "out of the box", but the behaviour is a bit ambiguous. Left-click does nothing, right-click shows a menu. When exiting, the icon is still in the tray and disappears only when you hover over it. I see that with other (non-Masm) applications, too.

:biggrin: there is an error in the code, so the logic breaks  :undecided: , one more example below  :azn:

hutch--

I guess no-one read the reason why I stuck with the task bar, its BIG enough to display the current memory status from the task bar without having to click on it where a half sized tray icon cannot display that much data. The lag on exit is Windows taking its time to clean up a running thread and it effects many applications. The left click is reserved for the three buttons and there is nothing to right click for, the memory status is already displayed on the interface.

Code is written on the KISS process, Keep It Simple Stupid.

> there is an error in the code, so the logic breaks

I did not understand this one.

LiaoMi

Quote from: hutch-- on June 30, 2019, 12:09:48 PM
I guess no-one read the reason why I stuck with the task bar, its BIG enough to display the current memory status from the task bar without having to click on it where a half sized tray icon cannot display that much data. The lag on exit is Windows taking its time to clean up a running thread and it effects many applications. The left click is reserved for the three buttons and there is nothing to right click for, the memory status is already displayed on the interface.

Code is written on the KISS process, Keep It Simple Stupid.

> there is an error in the code, so the logic breaks

I did not understand this one.

:biggrin: This refers to the example "Tray Icon Example" Periodically double icons appear in the panel and when the program is closed, the icon does not disappear.

Quote from: AW on June 29, 2019, 11:22:00 PM
Quote from: hutch-- on June 29, 2019, 09:12:54 AM
I think you can set that in Win10. I used to know how to do it in XP but that is some years ago.
I am sure they have invented some UWP wrapper for the old way people used to do it.

https://www.codeproject.com/Articles/74/Adding-Icons-to-the-System-Tray
But I think there are posts in this forum about that.

I am now interested in another example - "Sending toast notifications from desktop apps sample", especially for windows 10, example uses COM - https://code.msdn.microsoft.com/windowsdesktop/sending-toast-notifications-71e230a2/



Quickstart: Sending a toast notification from the desktop - https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/hh802768(v=vs.85), with this approach, when you hover the cursor on the icon, we could display the "toast notification" window.

Quote from: hutch-- on June 30, 2019, 12:09:48 PM
I guess no-one read the reason why I stuck with the task bar, its BIG enough to display the current memory status from the task bar without having to click on it where a half sized tray icon cannot display that much data. The lag on exit is Windows taking its time to clean up a running thread and it effects many applications. The left click is reserved for the three buttons and there is nothing to right click for, the memory status is already displayed on the interface.

Code is written on the KISS process, Keep It Simple Stupid.

> there is an error in the code, so the logic breaks

I did not understand this one.

On the other hand, for a good comfortable design, it is better to use the example with metro ui from fearless.. showing a small window when you hover the mouse and hiding in all other cases. This solution is easier.

Earlier hutch painted very beautiful windows - http://masm32.com/board/index.php?topic=7548.0 or http://masm32.com/board/index.php?topic=7535.0 or Demo using WM_NCHITTEST - http://masm32.com/board/index.php?topic=7498.0, something like this can be used for a small window and for counting memory  :angelic:

hutch--

 :biggrin:

Thanks, I was not sure what the comment was about. What I have tried to do is make the interface as small as practical, the app is 7.5k and still has an icon, manifest and version control block to shut up the crappy end of free AV scanners and has a processor usage that is so low it can hardly be measured, shows zero on both 100 and 1000 ms in task manager on my Win 10 64 pro. It still has the default 1 meg stack but that can be reduced if necessary because win64 does not use all that much stack except under unusual circumstances.

Now there are certainly ways of making it prettier and flashier but it also makes it fatter, slower and takes up a lot more screen space which is the antithesis of what I wanted it to do, have a small interface when it was running and a lot smaller when minimised. In the future there will be more and more very large memory applications, video processing is one that comes to mind but of course there are many others, the database folks, CAD, some games etc ... and being able to track active memory usage is important for the developer.

The final release software that a developer puts out into the wild should have memory tracking built into it but its not always available in an app while it is being developed.

jj2007

I would put a tiny borderless topmost window in the lower right corner, with a single percentage like 20% and a green background as long as there is no memory problem ahead; changing to yellow and eventually red if mem use increases.

It should disappear if user is scrolling something, or the mouse cursor is near, and reappear later automatically.

My 2cts :thup:

daydreamer

Quote from: hutch-- on June 30, 2019, 08:47:06 PM
Now there are certainly ways of making it prettier and flashier but it also makes it fatter, slower and takes up a lot more screen space which is the antithesis of what I wanted it to do, have a small interface when it was running and a lot smaller when minimised. In the future there will be more and more very large memory applications, video processing is one that comes to mind but of course there are many others, the database folks, CAD, some games etc ... and being able to track active memory usage is important for the developer.
thanks to this app,I have ordered much more memory
I have some Cg apps that easily can use many gigabytes,so its good to use to have a memory status tool
but mostly I combine a 3dmodeller and a 3dlandscape program which has  library with tons of premade materials and libraries of this and that,different skies and different objects
so first a lowpoly model and import  lots of procedural materials dont take up much memory
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding