[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Hashing in Lua
- From: Steve Dekorte <steve@...>
- Date: Mon, 03 Jul 2000 16:14:24 -0700
"Nick Trout" <email@example.com> wrote:
> The downside to this is ofcause performance and the problem with
> dertermining the cpu time for a function... Lua will never be "real-time".
> have a very good example.. I buildt a robot that used Lua for the AI...
> I had to stop the robot at some specific times when Lua did
> garbage-collection. If I kept it running while the garbage collection took
> place the robot might drive off-course in the 1/3 of a second it took to
One trick to avoiding this problem is create as few new tables as possible
program - since it's the tables that are garbage collected. For instance, if
doing vector math with tables like:
newtable = table1:add_(table2)
Instead of creating an returning a new table, have the operation apply to
table1 = table1:add_(table2)
And if you really need a new table for the result do something like this:
newtable = table1:clone()
newtable = newtable:add_(table2)
I've found that this technique not only avoids collecting excess garbage,
speeds up the program quite a bit since allocating memory for the new tables
can also be expensive.