lua-users home
lua-l archive

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


Dimitris Papavasileiou wrote:
Hi,
I was thinking of using lua to handle data files as well, that is make data
files like textures, models etc. lua files and have the interpreter load
them instead of writing parsers for everything. Anyway this is really neat
but I'm running into a potential problem: After loading the files and
getting them from lua some of them (like texture files) will not be useful
any more and since they might be quite big they'll waste quite some memory.
So the question is: if I GC those data will the memory be returned to the
system to be used by other processes?

Depends on the system; usually this memory wouldn't immediately
become available to *other* processes.

> I somehow doubt that but even then,
assuming that this memory was reserved by lua (or my process not sure about
this)

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

> and not used wouldn't th VM manager soon swap these pages out and use
the memory for more useful pages?

Sure, as long as there isn't still live, page-touching data somewhere
on the same page.

> What I want to say is: in any case I won't
waste physical RAM will I?

I wouldn't worry about it.  Lua has slightly unusual memory
habits (quite a lot of alloc/free churning and a lot of
page-touching in the current garbage collection implementation),
but nothing pathelogically leaky/fragmentory in practical usage.

--Adam
--
Adam D. Moss   . ,,^^   adam@gimp.org   http://www.foxbox.org/   co:3