lua-users home
lua-l archive

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

2009/6/11 steve donovan <>:
> 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?

Yes, if the 3D vectors were allocated on the heap using
run-of-the-mill malloc, then C++ would have problems too. (The memory
access patterns are often the bottleneck.) But in a normal C++
application the 3D vectors would be value types and live on the stack
rather than the heap and thus would be very quick to create and
destroy. But lua userdata must live on the heap, so in Lua we are
forced into the slow behavior.

Yes, for SIMD applications you could have a userdata representing an
"array of Vector3" and get very fast vectorized operations using a
library similar to NumPy. But in my case the issue is lots of small
computations that cannot be easily vectorized.

// Niklas