Hello guys, is there any way to limit the RAM usage and CPU usage of an application?
External program or even some algorithm that as soon as the memory usage reaches the limit the application no longer uses until a certain memory is released...
to limit the CPU I imagine that if I add a "delay (1)" in any loop, it will reduce the CPU usage a lot, however, I don't know if it is effective ...
can someone help me?
Have a way to limit RAM USAGE and CPU USA of a application ?
- skinkairewalker
- Enthusiast
- Posts: 634
- Joined: Fri Dec 04, 2015 9:26 pm
Re: Have a way to limit RAM USAGE and CPU USA of a applicati
In event loops where the WindowEvent() function is used instead of the WaitWindowEvent() function, the Delay() function should be included to prevent CPU hogging. Besides this, blocking-functions could also hog the CPU, and should be mitigated with timers, or with threads and semaphores.skinkairewalker wrote:Hello guys, is there any way to limit the RAM usage and CPU usage of an application?
As for memory usage, PureBasic maintains reference counting and does not release allocated resources unless explicitly done so. This is achieved by the various FreeXXX() functions, by nulling out variables, and by explicitly shrinking the string buffers through reduced allocations. Furthermore, procedural recursions could also cause memory leaks and stack overflows, and should thus be used with utmost care.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel
Re: Have a way to limit RAM USAGE and CPU USA of a applicati
@skinkairewalker
The use of delay() in some loops is essential for a fluid application / OS feeling for some operating systems.
Basically it helps the scheduler to distribute CPU resources.
The use of delay() in some loops is essential for a fluid application / OS feeling for some operating systems.
Basically it helps the scheduler to distribute CPU resources.
Thats why i consider missing (tightly integrated) asynchronous calling methods to be one of the biggest problems for PB.TI-994A wrote:Besides this, blocking-functions could also hog the CPU, and should be mitigated with timers, or with threads and semaphores.
Re: Have a way to limit RAM USAGE and CPU USA of a applicati
Which missing asynchronous calling methods?Bitblazer wrote:Thats why i consider missing (tightly integrated) asynchronous calling methods to be one of the biggest problems for PB.
There are threads for this and the finished message can be sent to the GUI via PostEvent.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
- skinkairewalker
- Enthusiast
- Posts: 634
- Joined: Fri Dec 04, 2015 9:26 pm
Re: Have a way to limit RAM USAGE and CPU USA of a applicati
thanks all ( TI-994A - Bitblazer - mk-soft )
but can I at least "measure" the amount of ram being used? to avoid that my users do not use more than the limit that I pre-establish?
but can I at least "measure" the amount of ram being used? to avoid that my users do not use more than the limit that I pre-establish?
Re: Have a way to limit RAM USAGE and CPU USA of a applicati
for your Windows process memory usage - viewtopic.php?f=13&t=76909
Re: Have a way to limit RAM USAGE and CPU USA of a applicati
In the Digi-clock code you will find a function which calculates the delay automatically.
You can see here in the gif how the delay is automatically adjusted.
When another function requests resources, the delay decreases again and levels itself again.
To do :
Look at the code.
You have to deal with this mechanism.
You have to create two parts, a sensor and a procedure to evaluate the sensor.
You can also copy out the function.
viewtopic.php?f=12&t=76880
You can see here in the gif how the delay is automatically adjusted.
When another function requests resources, the delay decreases again and levels itself again.
To do :
Look at the code.
You have to deal with this mechanism.
You have to create two parts, a sensor and a procedure to evaluate the sensor.
You can also copy out the function.
viewtopic.php?f=12&t=76880
地球上の平和
Re: Have a way to limit RAM USAGE and CPU USA of a applicati
It totally depends on the application I suppose, but I surely imagine you can keep track of roughly how much memory you are using by keeping a tally of the size of the objects you create/load/whatever in your program (at least an estimate). This seemed sufficient for my needs.skinkairewalker wrote:but can I at least "measure" the amount of ram being used? to avoid that my users do not use more than the limit that I pre-establish?
I would also like a solution for CPU limiting (by CPU percentage or so), however. I didn't look into it closely, but I think on most OS you can set the process priority which may get us somewhere close to it... but then again with threads, it's probably a bit harder.
Proud supporter of PB! * Musician * C64/6502 Freak