[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua language extension for complex number and vector values
- From: Geoff Leyland <geoff_leyland@...>
- Date: Mon, 4 Apr 2011 19:43:20 +1200
On 4/04/2011, at 6:25 AM, Luiz Henrique de Figueiredo wrote:
>> function f(a, b, z)
>> return a * exp(i*z) + b
>> end
>>
>> The problem of the function above is that it looks clear and simple
>> but in reality it is a disaster in term of run-time execution because
>> a lot of small objects have to be created on the heap every time that
>> it is executed.
>
> Indeed. I fell the same pain when I write bindings for math operations
> (and I've written several). I wish Lua told me that it wants a temporary
> value. I could then use static allocation for those.
>
> The only way out that I can see is to use an explicit block as in say
> complex.enter()
> complex.eval(a * exp(i*z) + b, a*b+z)
> complex.exit()
>
> Not nice, but doable.
>
> Can anyone see a better solution?
Would you care to explain how you can get the above to work? I thought maybe you mean that inside the block, everything is temporary, but I'm not sure that would work.
Thanks,
Geoff