lua-users home
lua-l archive

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


Unfortunately common expression evaluation creates tons of temporaries. :-(

pos = pos + vec1 + vec2 + vec3
pos = pos + ( pos3 - pos2 ) * 0.1        -- etc etc

What you're basically saying is that tables have to be used very sparingly
in expressions - but then what's the point of overriding __add etc. in the
metatables?

Its fine if you're running just one or two scripts, but I want to use Lua
*extensively*, ie. every object in my game will be running 2 or 3 Lua
"threads" (via my own job despatcher).  Some will be asleep, waiting for
signals etc. of course, but its still a lot of threads... creating a lot of
garbage.

---------------------------------
Q-Games, Dylan Cuthbert.
http://www.q-games.com

"John Belmonte" <jvb@prairienet.org> wrote in message
3F01A369.5080405@prairienet.org">news:3F01A369.5080405@prairienet.org...
> Dylan wrote:
> >>
> >>>frog = Vector{ 10, 20, 30 } + Vector{ 20, 30, 40 } + Vector{ 30, 40,
50 }
> >
> > Right now, If I have 400 aliens each doing pos = pos + vec1 + vec2 +
vec3, I
> > get a leak of 400x3x16=20K each frame.. at 60fps that's 115k a
second...6.9
> > meg a minute...4 gigabytes an hour... and that's without any lua table
> > structures or malloc overheads in my calculation.
>
> That's only if those vectors are literals, and you're naively reinstancing
them
> on every frame like in your frog example.  If you have any constants, it's
best
> to name them and keep them around in a table.  In other words, if it hurts
when
> you create stuff, don't create so much stuff.
>
>
> -- 
> http:// if   l .o  /
>
>