[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Functions and memory usage
- From: Basile STARYNKEVITCH <basile@...>
- Date: Wed, 16 Oct 2002 18:42:57 +0200
>>>>> "John" == John Donovan <JohnD@MagentaSoftware.com> writes:
John> Hi, I'm new to the list, and normally I'd just lurk for a
John> couple of weeks getting the feel for the list. However, time
John> is of the essence at the moment. We're developing a game on
John> a couple of well-known games consoles, and I've been given
John> the task of implementing a scripting system. After looking
John> at various options, I picked Lua. Now I'm trying to convince
John> my boss that Lua is A Good Thing. He's worried about memory
John> fragmentation. As most of you will be aware, consoles have
John> a very limited amount of memory, [...]
In my opinion the only real tool against memory fragmentation is a
moving (or copying, or compacting) garbage collector. The LUA GC is a
mark&sweep one, so it does not compact memory and neither does the
ordinary manual malloc+free (as in C) or new+delete (as in C++) memory
management. Fragmentation issues do appear in C or C++. There are lots
of literature on compacting or moving garbage collection (and there is
a GC mailing list, even if it is a bit quiet these days).
I am not sure that fragmentation is really an issue for game scripting
(I really don't know what these are exactly - I don't play games on my
computer, and never coded any game).
However, if you feel that fragmentation is an issue:
1. you cannot use traditional manual memory management (ie malloc+free
or new+delete) because it has the same fragmentation problem.
2. you should consider compacting or moving garbage collection
techniques, which do have some drawbacks (in particular, real-time
or interactive-time constraints may require tricky tradeoffs or
tuning with such moving GCs).
3. you could perhaps change Lua GC to be compacting. The simple case
would be to compact the memory once in a while, in your idle loop,
when the Lua call stack is nearly empty. If you do this, please
contribute (if possible) your compacting GC to the Lua community.
4. you might consider alternative scripting languages (or virtual
machines). I feel that Ocaml is a good scripting language, and its
garbage collection can be tuned to perform very well in an
interactive setting (like a game). Ocaml garbage collection is one
of the finest I know (it is generational, copying for new objects,
and marking & compacting for old ones). See www.ocaml.org
5. You might use a copying GC in C. This is painful but doable. My
Qish runtime is actually such a beast. See my home page and/or send me
email.
[Sorry for mentionning another language on the Lua mailing list, but I
think that there are cases where Lua might not be the best solution]
Regards.
--
Basile STARYNKEVITCH http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net
alias: basile<at>tunes<dot>org
8, rue de la Faïencerie, 92340 Bourg La Reine, France