lua-users home
lua-l archive

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

steve donovan kirjoitti 11.6.2009 kello 19:29:

On Thu, Jun 11, 2009 at 6:19 PM, Asko Kauppi<> wrote:

And you cannot override add and sub and mul and... either. Meaning you
want userdata.

Case closed?  :))

Thinking about 3D vectors as objects, I'm sure a C++ application would
struggle with lots of tiny objects like that, and it would certainly
cause a lot of allocation churn unless some clever reusing was going
on.  Surely the userdata needed here is an _array_ of 3D vectors, to
efficiently handle the storage and processing of many vectors?

steve d.

This brings to mind the way I solved it for FMI's server (a separate mail today).

A Matrix2D object keeps internally two references to Matrix objects (x and y). This makes the "array of float" be the only needed abstraction, and others are derived from it.

The approach has many implied benefits, s.a. avoidance of C++ copy constructors in many cases (we can push a new reference to the .x part since its already a Lua object). Also, optimized arithmetic operations (SSE code) can be applied to Matrix2D without any rewrite.