[SDL] I Need a Game Interpreter

Bob Pendleton bob at pendleton.com
Mon Sep 2 16:58:01 PDT 2002

Matthew Bloch wrote:
> On Monday 02 September 2002 03:13, Robert Clayton wrote:
>>I really like Lua.  I'm using it as the scripting embedder for writing
>>events in our games.
>>I understand that the garbage collection method (mark and sweep) isn't
>>great for games, but I really haven't had a problem.
>>From experience: don't *ever* use an automatic, garbage-collected runtime for 
> a game.  I've spent many painful hours with Ruby trying to stop it from 
> messing up my frame rate and only partially succeeded, much as I love the 
> language for other jobs.  Once you've built your foundation on such a runtime 
> there's very little you can do about it when you notice your game jerks every 
> few frames.  Mark and sweep garbage collection involves forgetting about 
> memory that you've allocated and every so often traversing an enormous tree 
> of pointers to reclaim some memory.  If you don't do it, or delay it much, 
> your program will run out of memory.  Do it as often as the language wants, 
> and you'll never get a consistent frame rate.  There's also nothing you can 
> do to interrupt it-- once the recovery algorithm starts it must run to 
> completion or start from scratch.

The simple way around that is to use static allocation. Just 
pre-allocate all the structures you are going to use in advance, just 
like in C/C++, and you won't every see GC pauses.

After the initialization, do one force the GC to run to clean up the 
memory footprint. Then, it you *must* use operations that generate 
garbage at runtime monitor the growth of the heap and do a GC when it is 
convenient, like when you pop up a dialog.

I've used this approach in Lisp and Java and it works very well. But, it 
does require a great deal of discipline while writing the code.

		Bob Pendleton

> Python uses reference counting to automatically free memory, and so the work 
> of reclaiming memory is spread evenly over execution, rather than 
> concentrated into long lumps as with GC.  See:
>   http://www.gamasutra.com/features/20020821/dawson_01.htm
> For how one software house's story.  This has been a public information 
> broadcast from someone who's learnt his lesson with garbage collection and 
> games :)  I'd be intereseted to know if anyone has used a GC as the sole 
> storage solution for a game, or whether (as many people do) it's just used as 
> a backstop between levels to tidy up loose ends.

+ Bob Pendleton, consultant for hire +
+ Resume: http://www.jump.net/~bobp  +
+ Email:  bob at pendleton.com          +

More information about the SDL mailing list