lua-users home
lua-l archive

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


As in coding choices or changes in Lua's implementation?

The key choice I've seen within scripts is to try to reuse temporaries more
aggressively. This can be done in a couple of ways:

1. If you've got a loop that calls code that needs a table or a userdata,
allow the table to be passed into it. To make it "pleasant" to use make the
parameter that does this optional. Then the code outside the loop can
allocate once and reuse.

2. If you can statically manage the lifetime of an object, then you can keep
a table of them available for recycling. Allocate becomes:

    table.remove( supply ) or allocate()

And "free" becomes:

    table.insert( supply, obj )

You can toss the pool when done by setting it to the empty table.

Within Lua's implementation, I've found that careful rearrangement of the
structure of a table entry can shave a significant percentage of the space
while still preserving alignment for doubles. See my earlier messages on the
subject.

Mark

on 8/27/04 11:48 AM, Nick Trout at nick@rockstarvancouver.com wrote:

> 
> So, this is quite an opened question and I have few ideas but I'd like
> to throw it out open... What ideas do people have for reducing the
> memory consumption of Lua in working scripts?
> 
> Nick
>