The MASM Forum

Microsoft 64 bit MASM => Tools & Toys => Topic started by: hutch-- on June 26, 2019, 05:29:09 AM

Title: Memory Status Toy, Memstat.exe
Post by: hutch-- on June 26, 2019, 05:29:09 AM
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.
Title: Re: Memory Status Toy, Memstat.exe
Post by: LiaoMi on June 26, 2019, 06:58:23 AM
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:
Title: Re: Memory Status Toy, Memstat.exe
Post by: 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


Get the one below.
Title: Re: Memory Status Toy, Memstat.exe
Post by: LiaoMi on June 28, 2019, 05:52:21 AM
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:
Title: Re: Memory Status Toy, Memstat.exe
Post by: AW on June 29, 2019, 04:38:26 AM
I am needing something like this as a Tray Icon  :icon_idea:
Title: Re: Memory Status Toy, Memstat.exe
Post by: 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.
Title: Re: Memory Status Toy, Memstat.exe
Post by: AW on June 29, 2019, 11:22:00 PM
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.
Title: Re: Memory Status Toy, Memstat.exe
Post by: hutch-- on June 30, 2019, 02:12:48 AM
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.
Title: Re: Memory Status Toy, Memstat.exe
Post by: 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.
Title: Re: Memory Status Toy, Memstat.exe
Post by: LiaoMi on June 30, 2019, 07:41:04 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:
Title: Re: Memory Status Toy, Memstat.exe
Post by: 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.
Title: Re: Memory Status Toy, Memstat.exe
Post by: LiaoMi on June 30, 2019, 07:17:58 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.

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/

(https://www.whitebyte.info/wp-content/uploads/2015/09/csharp-toast.png)

Quickstart: Sending a toast notification from the desktop - https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/hh802768(v=vs.85) (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.

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 (http://masm32.com/board/index.php?topic=7548.0) or http://masm32.com/board/index.php?topic=7535.0 (http://masm32.com/board/index.php?topic=7535.0) or Demo using WM_NCHITTEST - http://masm32.com/board/index.php?topic=7498.0 (http://masm32.com/board/index.php?topic=7498.0), something like this can be used for a small window and for counting memory  :angelic:
Title: Re: Memory Status Toy, Memstat.exe
Post by: hutch-- on June 30, 2019, 08:47:06 PM
 :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.
Title: Re: Memory Status Toy, Memstat.exe
Post by: jj2007 on June 30, 2019, 09:48:23 PM
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:
Title: Re: Memory Status Toy, Memstat.exe
Post by: daydreamer on July 02, 2019, 03:58:14 AM
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
Title: Re: Memory Status Toy, Memstat.exe
Post by: daydreamer on July 11, 2019, 03:29:07 AM
upgraded to memory to 20gb so I can try out the huge memory advantage in 64bit,not because I want to bloat it,but that produce something fast,that isnt stopped by 32bit mode memory "walls"
Title: Re: Memory Status Toy, Memstat.exe
Post by: Antariy on July 12, 2019, 11:21:58 AM
According to talks about tray icon indicators, just some idea aloud.
RAM Clear (look at signature below this message) has a feature to show free RAM in the Tray Icon - as a digital indicator in the percentage manner.
It's C(++) code, and, as described in its thread, is not neat, multiple times rewritten/extended without real refactorization to make it greater looking, lol, so won't post the sources there/here.
But the idea was to create a bmp (in memory, GDI), then to draw to it the percentage number with text (like TextOut, in other words, GDI also), then create simple icon with using that bmp, then draw that icon on the taskbar/tray. Remember to calculate in realtime the size of text to fit it into the center/centre of the icon exactly, or predetermine it before an action (to hardcode it) depending on the size of an icon you will make, and the type of font you will use (monospaced fonts are a lot easier to use in this hardcoded way, just use pixel-size when you create it).
Title: Re: Memory Status Toy, Memstat.exe
Post by: AW on July 12, 2019, 05:51:31 PM
I had a gadget in Windows 7 for Memory Status and CPU usage, then Microsoft cut all the fun short by abolishing sidebar gadgets in Windows 10 (Windows 8.x as well). I never believed Microsoft reasons for that (and they never showed concrete cases of security issues or proved they could not mitigate them case they existed) - all they really wanted was to replace these little funny toys with appstore jumbo size crap - but failed.   :skrewy:
Title: Re: Memory Status Toy, Memstat.exe
Post by: fearless on July 13, 2019, 11:37:47 PM
Thanks. I haven't updated the TrayMenu library in a while, but had thought of exposing the function that creates the transparent icons with text - Another user on tuts4you was using it for a cpu load type thing - and I thought of creating another function where you could pre-create all the icons required "0%", "1%",..."99%"" and just store them in an array of icon handles so that you could just fetch the icon for whichever percent value you wanted to display. Might try and get round to adding that in future. Although the benefit of dynamically creating them is if say you had a preferences in your app and user wanted to specify a color for the text.

I created something similar in another app i created to monitor my qnap nas box:
(https://i.postimg.cc/k5Xnfy4L/qnapmonitor.png)
The first 4 icons are for the qnap for temperature and cpu usage. The other text based icons in the tray area are from CpuTemp and MSIAfterburner
Title: Re: Memory Status Toy, Memstat.exe
Post by: hutch-- on July 14, 2019, 02:08:33 AM
Rudi suggested some time ago to make a showcase for members to show completed applications and while it is a good idea, the risk is it would end up full of crap and to delete the crap would end up putting at least some people's nose out of joint. Most of the stuff in this thread should not be here as this sub forum is for 64 bit MASM code.

Any feedback on the idea of a showcase would be welcome.