Finding available memory without shell, how to use hasMemory()

Mark Wieder mwieder at ahsoftware.net
Sun Feb 23 21:09:49 EST 2014


Gabriel-

Thursday, February 20, 2014, 11:07:59 AM, you wrote:

> Hey All,

> I am working on a program where I need to know the amount of available
> memory.

> I'm running on OS X and hasMemory() appears to return true/false for the
> same values regardless changes to free/available memory. Is there some
> trick to getting hasMemory() to correspond with the actual available
> memory? Is this possibly something that is being addressed in newer
> versions of LiveCode?

Ah, the curse of modern operating systems...

What the hasMemory() function does is allocate and then free the
specified amount of memory, and then returns a boolean telling whether
it was successful. However, before doing that, it casts the desired
amount as a uint4, which limits the amount to 2147483647. If you're
trying to see if more than 2G of memory is available, that won't help.
And because modern operating systems will very happily exchange chunks
of memory out to swap files when necessary, it's unlikely that you'll
see the malloc fail, and thus you should see a "true" return value.

Are you doing something where you really need to see the actual free
ram without the swap/inactive memory? The "available" term here is a
bit ambiguous, and depends on your needs.

-- 
-Mark Wieder
 ahsoftware at gmail.com

This communication may be unlawfully collected and stored by the National 
Security Agency (NSA) in secret. The parties to this email do not 
consent to the retrieving or storing of this communication and any 
related metadata, as well as printing, copying, re-transmitting, 
disseminating, or otherwise using it. If you believe you have received 
this communication in error, please delete it immediately.





More information about the use-livecode mailing list