[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: optimising table creation; garbage collection
- From: "Jim Whitehead II" <jnwhiteh@...>
- Date: Wed, 23 Aug 2006 07:22:48 -0400
I'm pretty heavily involved in writing and developing addons for World of Warcraft using LUA, and based on the event driven (and graphic update driven) nature of the system, there are times when we need to create tables in response to these events or frame updates. Since WoW is using lua
5.0.2, we don't have the luxury of incremental garbage collection, At times, the game will hiccup during a GC cycle (some machines are affected more than others, obviously.)
The immediate answer to your question as I understand it is no, the __gc metamethod only applies to userdata, so there's no easy way to auto-recycle these tables. That being said, there are a few things you can look at:
1.) If the lifetime of the table is only within the function, you can create a single table outside the function and clear it at the beginning of the function. While you incur the overhead of the iteration and nil'ing the elements, you will only create key,value garbage in this manner, as opposed to full fledged table garbage.
2.) There already exists a very good table recycling system called "Compost", written by Tekkub. While its written specifically for the WoW context, it would be trivial to adapt it to your system.
Again, the bigger question asked by David is whether or not the overhead of the table management (i.e. manually allocating and releasing) is somehow more acceptable than the garbage you're creating.
- Jim
On 8/22/06, Damian Stewart <damian@frey.co.nz> wrote:
hi
i'm writing some code that at the moment does a lot of dynamic table
creation, ie local bob = {}.
in order to get around this i thought of writing a RunTimeTableManager
object which manages a table pool, and which i can query for new tables
each time i want one, ie local bob = RunTimeTableManager.NewTable(), at
which point the table is removed from the RunTimeTableManager's pool.
what would be nice is for the tables to automatically return themselves to
the RunTimeTableManager's pool when they were done with being used. can i
do this with the garbage collector? if each table i return from
RunTimeTableManager.NewTable() has a __gc method which pushes the table
back into the RunTimeTableManager's pool, will this cause things to explode
in ugly ways?
cheers
d
--
f r e y
live music with machines
http://www.frey.co.nz