lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Adam Moss esciribió:

> Lua uses the usual C heap functions to manage memory, so the
> memory simply belongs to your process like any other of the
> process's heap.  (So at least, memory freed in lua's gc cycle is
> usually immediately reusable by the lua-using process.)

Very true. Whether the memory is returned to the OS or not is
completely dependent on the malloc implementation. Some
implementations on some OS's use system functions like 
madvise(2) to tell the OS that the data on a page is no
longer of interest, allowing the OS to completely recycle
the page. For example, the FreeBSD default allocator can
be told to do so by using the "H" MALLOC_OPTIONS flag.
This can be a big help if the system is paging a lot, but
the extra system call can slow performance if there is no
paging.

Linux, I'm told, uses an optimistic VM allocation system
which does not verify that swapping space is actually
available before allocating virtual memory to a process.
Under these circumstances, returning memory to the OS
can be dangerous: it might crash the application later
on when an attempt is made to reuse the virtual address.

I don't know anything about Windows except that the
memory allocator seems to be much slower than the other
mallocs I'm used to using.