lua-users home
lua-l archive

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

On 29/10/2011 9:50 PM, Mike Pall wrote:
Ross Bencina wrote:
Here's an example of the kinds of eager resource deallocation I'm
thinking of:

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.

Are there other options or approaches I should know about?

Thanks Mike

That would certainly solve the issue with temporaries. I have a couple of questions about that post:

I'm a little unclear whether that technique can be used to deal with "crystalised" (evaluated) vectors/matricies. It seems to me that once the internal expression tree has been evaluated, and that evaluated datum is referenced by a Lua variable, then it's lifetime is subject to the usual Lua GC. Is that correct?


a = b + c + d
print (a[1]) -- access an element of a. causes the expression tree to be evaluated.

My understanding is that the datum pointed to by 'a' would now be subject to usual Lua object lifetime. Does your approach have a way to avoid this?

In that post you write:

> In the case of a vector/matrix library for Lua I suggest using
> fixed size userdata objects. They can hold up to a fixed size
> expression in a plain list (in postfix order). This avoids
> problems with tree reference counting and should be good enough
> for most practical purposes.

How would this work if an expression is used at two sites, e.g.:

a = x + y

b = z + a

c = f(a)

d = g(b)

I'm not seeing how the common subexpression x+y would be evaluated only once without "tree reference counting". Do I understand correctly? Are you assuming this case is uncommon on practice?

Thank you