get physical memory usage of the computer

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

get physical memory usage of the computer

Post by Doctory »

is there a function or something that gets the physical memory usage of the computer?
User avatar
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

Post by kikito »

This:

Code: Select all

collectgarbage("count")
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.
When I write def I mean function.
User avatar
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

Re: get physical memory usage of the computer

Post by Doctory »

i dont want to get the usage of my program, i want to get the usage of my entire computer
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: get physical memory usage of the computer

Post by ivan »

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.
User avatar
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

Post by slime »

Doctory wrote:i dont want to get the usage of my program, i want to get the usage of my entire computer
That's not possible at the moment.

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.
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: get physical memory usage of the computer

Post by ivan »

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'

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
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. :)
User avatar
I~=Spam
Party member
Posts: 206
Joined: Fri Dec 14, 2012 11:59 pm

Re: get physical memory usage of the computer

Post by I~=Spam »

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'

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
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. :)
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.

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
User avatar
Inny
Party member
Posts: 652
Joined: Fri Jan 30, 2009 3:41 am
Location: New York

Re: get physical memory usage of the computer

Post by Inny »

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.
Post Reply

Who is online

Users browsing this forum: No registered users and 202 guests