maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   How to get volume of a free RAM? (https://talk.maemo.org/showthread.php?t=53226)

Grinchman 2010-05-21 04:56

How to get volume of a free RAM?
 
Hello,
I want to know how many RAM on N900 is free before I start some operation in my Qt app. I thinked that I`ll can get this info from HAL, but in list of devices /org/freedesktop/Hal/devices/ I don`t found something about RAM.

EDIT:
So, I found some solution. I read from file /proc/meminfo lines with memory usage. Maybe does anyone know a more elegant solution?

Joorin 2010-05-21 06:13

Re: How to get volume of a free RAM?
 
Why do you want to know this?

And, more specifically, are you looking for how much memory you would be able to allocate with one call to malloc or how much you see marked as "Free" using the command top?

The file /proc/meminfo contains a lot of information but be careful with what you actually ask for.

ossipena 2010-05-21 06:17

Re: How to get volume of a free RAM?
 
what do you need the info for?

there is a possibility that you don't have to worry about free ram at all.

qwerty12 2010-05-21 06:22

Re: How to get volume of a free RAM?
 
There's probably a "UNIX Way" but /usr/include/osso-mem.h (part of the libosso library that is standard on Maemo) has functions to do what you want.

Grinchman 2010-05-21 06:42

Re: How to get volume of a free RAM?
 
I need this because my app in some time run function, which needs much free memory and I want prevent it uses if free RAM is not enought.

ossipena 2010-05-21 06:57

Re: How to get volume of a free RAM?
 
doesn't os free up ram if needed? or was this only in OS2008?

fnordianslip 2010-05-21 07:50

Re: How to get volume of a free RAM?
 
Linux allocates RAM optimistically, that is it will appear to allocate blocks with new and malloc but not actually allocate them until they are used, and may use swap then if it has overallocated beyond its means.

Joorin 2010-05-21 09:03

Re: How to get volume of a free RAM?
 
Quote:

Originally Posted by Grinchman (Post 668809)
I need this because my app in some time run function, which needs much free memory and I want prevent it uses if free RAM is not enought.

You still haven't defined "free memory".

The N900 has ~1GByte of "memory" with 256MByte as actual RAM capsules and the rest as swap on disk. The swap on my phone is typically not used at all, even after several days of usage, so it's possible to say that ~740MByte of memory is "free" no matter what.

So, if your function needs, say, 100MByte and 235MByte of capsule RAM is allocated, you have 20MByte of capsule RAM and 740MByte of swap left. Would you say that this is enough to run your function or do you need to have 100MByte of capsule RAM available?


All times are GMT. The time now is 20:19.

vBulletin® Version 3.8.8