[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Vectors/Atomic Tuples/Garbage Collection
- From: "Dylan Cuthbert" <dylan@...>
- Date: Tue, 1 Jul 2003 10:43:33 +0900
> Don't be afraid to let these vectors exist as either your native aligned
format
> or a Lua array depending on what is convenient. You just need to be able
to
> translate between the two. So I'd rewrite what you have above as:
>
> position = Vector { 10, 20, 30 } -- Vector_XYZ is assumed
> position.another_value = 10 -- ERROR
> position:Set(Vector_X { 30 }) -- you might also support
Vector_X(30)
> -- for efficiency
> position:Set(Vector_XY { 50, 70 })
Ok, some questions
With heavy user data when I do position = vector, a reference is taken,
right, when I modify it a copy is taken (via those Vector calls). How and
when is the memory freed? If this user data is a C++ class do I still have
to use malloc/free with a positional new?
I can imagine there being a whole ton of temporary 12-16 byte vectors (not
including the overheads on the Lua side for methods and metatables) being
malloced, I mean an *absolutely friggin' huge* amount as the game progresses
frame to frame - these are only destroyed when the time-consuming garbage
collector is run, right? (something you don't want to run whilst the game
is running or you might drop a frame)
So I'm coming to the conclusion that Lua is great for math when it involves
atomic types, but as soon as you start trying to use table-like constructs
in the same way the garbage begins to pile really high. Or maybe it happens
even with the atomic types? :-/
ie.
frog = 10 + 20 + 30 + 40 + 50 + 60
Are 6 "value" objects created here and not deleted until the garbage
collector runs?
frog = Vector{ 10, 20, 30 } + Vector{ 20, 30, 40 } + Vector{ 30, 40, 50 }
Are 3 Vector userdata (or table) objects created and not deleted until the
garbage collector runs?
Or is there some concept of temporaries - cleaning up of values that haven't
been assigned by the end of the expression stack?
Regards
---------------------------------
Q-Games, Dylan Cuthbert.
http://www.q-games.com
"John Belmonte" <jvb@prairienet.org> wrote in message
news:3F00799E.5080702@prairienet.org...
> Dylan wrote:
> > Something like (this is totally off the top of my head.. don't rip me
to
> > shreds)
> >
> > position = << 10, 20, 30 >> -- create a "tuple"
> > position.another_value = 10 -- ERROR.. position isn't a table and is
a
> > "const" in effect
> >
> > position<<x>> = 30 -- creates a new "const" vector with x as 30
and
> > the rest from position
> > position<<x,y>> = 50, 70 -- writes to x, y, and takes z from position,
> > creating a new vector
>
> I haven't been following this thread too carefully, but userdata is what
you
> want. It seems like you are on that path anyway.
>
>
> -- other stuff
> lua_array = position.ToArray()
> lua_array[0] = 25.5 -- assuming you break Lua
convention and
> -- start your array at 0 :-(
> position_b = Vector(lua_array)
> position_c = position * position_b -- your efficient native operation
> point = Vector_XY(position_c) -- extract XY as vector
> z = Vector_Z(position_c):ToNumber() -- extract Z as Lua number
> z = position_c:ToArray()[2] -- same thing
> z = position_c:GetScalarZ() -- same thing
> point_b = Vector(point) -- copy
>
>
> If you haven't seen it, "Vector { 1, 2, 3 }" is table constructor syntax,
> equivalent to Vector({1, 2, 3}).
>
> This isn't too far off from your C++ vector template stuff...
>
> -John
>
>
>
> --
> http:// if l .o /
>
>