get physical memory usage of the computer
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
get physical memory usage of the computer
is there a function or something that gets the physical memory usage of the computer?
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: get physical memory usage of the computer
This:
Returns the amount of memory consumed by your process. I think it only counts the size of Lua objects though, not LÖVE C++ objects (if I understood it correctly, a 5MB soundfile takes the same amount of Lua space than a 2kb one). I don't know if it's possible to print the memory allocated including C++ objects.
Code: Select all
collectgarbage("count")
When I write def I mean function.
Re: get physical memory usage of the computer
i dont want to get the usage of my program, i want to get the usage of my entire computer
Re: get physical memory usage of the computer
Lua is designed be cross-platform so it doesn't provide direct accesss related to the operating system or hardware like "total ram available" or "ram used by other OS processes".
There is "os.getenv" which lets you access some "environment variables" but that about it.
There is "os.getenv" which lets you access some "environment variables" but that about it.
- slime
- Solid Snayke
- Posts: 3132
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: get physical memory usage of the computer
That's not possible at the moment.Doctory wrote:i dont want to get the usage of my program, i want to get the usage of my entire computer
It's also not very meaningful on a lot of platforms. Many systems will share memory between the CPU and the GPU (and the amount given to the GPU may change dynamically), many will page out memory to the hard drive if physical RAM starts getting scarce, some will compress infrequently-used parts of RAM, etc. etc.
Re: get physical memory usage of the computer
It might be possible to get some
information about the currently running processes on Windows
using the command line via os.execute.
For example, using 'tasklist'
Tasklist (available on Vista and XP Professional, n/a on XP Home) is nice because it can output directly to csv.
And there is another tool that gets the total physical memory too but again
this is for debug purposes only and should not be used in serious code.
The problem with code like this is that the user turns off some Windows service and your script stops working.
information about the currently running processes on Windows
using the command line via os.execute.
For example, using 'tasklist'
Code: Select all
function processmemusage()
local handle = io.popen('tasklist /fi "Imagename eq love.exe"')
local result = handle:read("*a")
handle:close()
result = string.match(result, ' ([^%s]-) K') or 'n/a'
return result
end
And there is another tool that gets the total physical memory too but again
this is for debug purposes only and should not be used in serious code.
The problem with code like this is that the user turns off some Windows service and your script stops working.
Re: get physical memory usage of the computer
It seems that this is the best way. An external library or modified LOVE source will need to be used to add this kind of support. On unix-like systems you would use the "free" command.ivan wrote:It might be possible to get some
information about the currently running processes on Windows
using the command line via os.execute.
For example, using 'tasklist'Tasklist (available on Vista and XP Professional, n/a on XP Home) is nice because it can output directly to csv.Code: Select all
function processmemusage() local handle = io.popen('tasklist /fi "Imagename eq love.exe"') local result = handle:read("*a") handle:close() result = string.match(result, ' ([^%s]-) K') or 'n/a' return result end
And there is another tool that gets the total physical memory too but again
this is for debug purposes only and should not be used in serious code.
The problem with code like this is that the user turns off some Windows service and your script stops working.
But as said before, this number can be pretty meaningless if graphics memory is shared. So why do you need this? That seems very silly. All I can think of is that you want to make your program try to only use memory that you system has left (without going into swap). I think you should just allow the user to specify a target memory of the application. It is at a reasonable default but it can be changed by those who want to (just like java can).
My Tox ID: 0F1FB9170B94694A90FBCF6C4DDBDB9F58A9E4CDD0B4267E50BF9CDD62A0F947E376C5482610
Re: get physical memory usage of the computer
Memory usage of the computer is a useless metric, because in an ideal world you would use 100% of it, and only have as many GB of RAM as was necessary to run your software. In a real world, most software tries to run in a "cache friendly" way. For instance, Firefox, which has been long accused of being a memory hog, is keeping images and pages in memory so that when you press the back button, it can return to that page quicker. And even then, the operating system is doing its best to keep programs in memory before you need them, or after you're done with them, so that if you start that program it'll be ready quicker.
From the point of view of a game written in a managed language, you want to be mostly concerned with how often Garbage Collection is happening. If it happens periodically (like once every few seconds or 15 seconds) then you're doing awesome. When garbage collection is happening multiple times a second, then you may see frame-rate drops. Otherwise, your operating system, other programs, and the underlying mechanisms of LOVE itself, are all conspiring to make sure that you don't have to worry about memory usage.
Just don't do anything stupid like load full MP3s into memory with love.sound.newSoundData, you want to stream those with love.sound.newDecoder.
From the point of view of a game written in a managed language, you want to be mostly concerned with how often Garbage Collection is happening. If it happens periodically (like once every few seconds or 15 seconds) then you're doing awesome. When garbage collection is happening multiple times a second, then you may see frame-rate drops. Otherwise, your operating system, other programs, and the underlying mechanisms of LOVE itself, are all conspiring to make sure that you don't have to worry about memory usage.
Just don't do anything stupid like load full MP3s into memory with love.sound.newSoundData, you want to stream those with love.sound.newDecoder.
Who is online
Users browsing this forum: No registered users and 202 guests