lua-users home
lua-l archive

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


Title: RE: [lua-l] Lua gc in games

Sorry to jump in so late on the thread.

But I'm curious, rather than modify Lua's garbage collection, why not have your own object manager do it?  In this case, Lua's pretty much just tossing references, while the bulk of deallocation is done by your engine, which could leverage it's own memory manager. 

Create a gc tag method, and simply set a flag or whatever your object manager needs, and then you needn't worry about Lua so much.

Brian

-----Original Message-----
From: lua-l@yahoogroups.com [mailto:lua-l@yahoogroups.com]
Sent: Tuesday, August 07, 2001 2:51 AM
To: lua-l@yahoogroups.com
Subject: [lua-l] Digest Number 427

Message: 2
   Date: Mon, 6 Aug 2001 16:28:00 -0700
   From: "Josh Jensen" <joshj@microsoft.com>
Subject: RE: Lua gc in games

> > The idea is more that you only collect the "young"
> generation most of
> > the time (a "minor" collection), and then collect the "old"
> generation
> > when you're really running out of heap (a "major" collection).
>
> I was a little off on what I thought generational meant,
> thanks for the clarification. This sounds basically like my
> const data idea, I guess the only difference would be that I
> was proposing that the user would give the GC a hint about
> where "old" ends and "young" begins.
>
> what I think its going to do. The other is that operations
> that would seemingly create no new memory, actually do. At
> least, Lua updates its "rough approximation of used memory."

Amped just got hit by the lua_newuserdatabox() allocation in Lua 4.1 Alpha.  This wasn't a problem before, I'm pretty sure, but the new semantics of user data made it so.  A simple function call that passed a user data value to Lua and was called quite a few times per frame caused frame rates to drop considerably because of all the allocations going on.  I was able to remedy the problem, but it certainly wasn't a place I expected an allocation.

> Hopefully!
> This would require some serious looking at. Many games allow
> up to hours of continuous gameplay. However, in practice most
> people at least Save once in a while, or pause to take a
> bathroom break. Other games, such as Amped, could probably
> make a large estimate of 10-20 minutes before the user stops boarding.

Thankfully, the in-game portion of Amped that uses Lua is very, very careful about anything that allocates memory (read: it rarely, if ever, happens).  Still, though, I could have scripted more of Amped if I wasn't so paranoid about the garbage collection process.

Thanks,
Joshua Jensen
Amped: Freestyle Snowboarding
http://www.xbox.com/Games/sports/amped.htm