Mark Waddingham mark at livecode.com
Fri Jun 10 05:21:23 EDT 2016

On 2016-06-10 10:05, Mark Waddingham wrote:
> P.S. The 'hasMemory' function in LiveCode actually does the best it
> can do - it sees if it can allocate a contiguous block of memory of
> the size that has been requested (using malloc) and if that succeeds,
> it frees the block and returns true. This should mean that (assuming
> nothing on the system suddenly consumes all physical and virtual ram)
> you should be able to do an action which requires that amount of
> memory immediately after:
> void MCLegacyEvalHasMemory(MCExecContext& ctxt, uinteger_t p_bytes,
> bool& r_bool)
> {
>   char *t_buffer = nil;
>   r_bool = nil != (t_buffer = (char*)malloc(p_bytes));
>   free(t_buffer);
> }

As an addendum, Fraser just reminded that even this is entirely useless 
on Linux.

When you request more memory to a process on Linux, the kernel will 
happily grant *all* requests which will fit in the address space - it 
allocates pages (whether they be physical or virtual) *lazily*. So you 
can quite happily do malloc(2^46) and it will succeed... You'll just get 
a SEGV at some point later when there are no pages anywhere left. (Linux 
has an overcommit policy - i.e. it does not use the number of possibly 
available pages to determine how much address space it will give each 

Warmest Regards,


Mark Waddingham ~ mark at livecode.com ~ http://www.livecode.com/
LiveCode: Everyone can create apps

More information about the Use-livecode mailing list