lua-users home
lua-l archive

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

Petri Häkkinen wrote:
> Have you considered adding support for native 2d/3d/4d vector
> types? I think this would make many game developers including me
> very happy. Allocating and garbage collecting hundreds or even
> thousands of temp vectors created each frame is currently a
> waste of precious CPU cycles.

You'll be able to create _any_ C type at runtime from pure Lua
code. E.g. this creates an array with 1000 vectors:

    typedef struct { double x,y,z; } vector;

  local v ="vector[1000]")

This needs exactly the same amount of space as it would take in
C/C++. But of course you should be just as reluctant as in C/C++
when using 'new'. Even in C you need to recycle or pool objects if
you want maximum performance.

It's hard for any compiler to eliminate the allocation overhead if
you create tons of small temporary objects and pass them around
everywhere. I'll be adding some more optimizations for this in the
future, but there's a limit to that. E.g. storing tiny cdata
objects in plain Lua tables is simply not a good idea. Store them
in an array of their respective type and you'll be fine.