[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: rapid lifetime based collection of transient user data objects?
- From: Ross Bencina <rossb-lists@...>
- Date: Sat, 29 Oct 2011 13:56:38 +1100
I would like to know about available techniques for achieving
eager/rapid collection of short-lived user data in Lua. I'm thinking of
things like scope-based, static-lifetime based GC hinting, or maybe
I notice that there has been discussion in the past, some related to
resource cleanup for exception handling  and some related to rapid
temporary resource recycling . My interest is in the latter.
What I have in mind is a vector processing system where "vector objects"
are used with the same syntax used for numbers in lua (infix operators,
functions returning vectors etc). I would like to achieve efficient CPU
data cache usage for large temporary user data objects by reusing the
same objects rather than having a bunch of temporary and intermediate
values polluting the cache until the GC collects them.
Here's an example of the kinds of eager resource deallocation I'm
In an expression such as the following, where a, b, c, d are user data:
a = (b + c) + d;
the subexpression b+c will generate a temporary user data.
1) I would like the (b+c) temporary to be collected/freed/recycled
directly after the temporary's last use.
2) If it can be known that this expression is the last use of either b,
c, and/or d, I would like those objects to also be
collected/freed/recycled at that point.
I understand that this is not how GC usually works but is there some way
to achieve this in Lua without resorting to explicit allocation and
Given that these user data are number-like and cannot hold references to
other objects, I think one approach might be to use reference counting.
Also at least within expressions, and for objects created and used only
in a single scope, it might be relatively easy to determine their
lifetime using static analysis.
It looks like LuaRC/LuaPlus [3, 4] reference counting system might be
one possible approach. Does that seem like a good fit for what I've
described above? Are there other options or approaches I should know
about? How have other people solved this problem? Are these issues being
considered at all for main-line Lua development or are they considered
out of scope?
Thanks very much,
 Subject: [Patch] Finalization of function objects
 Lua: Improving deterministic resource cleanup
 Subject: Re: Reference counting patch for Lua 5.1?