lua-users home
lua-l archive

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


Adam Strzelecki wrote:
> Yeah, also I wished there was a way to get number of elements of
> FFI allocated VLA. I wonder if FFI does remember that somewhere,

It knows the size in bytes, not the number of elements. But this
info may be hard to derive in the future with the new GC in 2.1.
That's why I'm not exposing it to the outside.

> I think it does as there's an optimizer option to disable/enable
> checking for VLA index ranges.

Err, no. If you mean -Oabc, then this is an optimization to
eliminate the bounds-checks for Lua tables. However this is only
done, when it's safe to do so and when the bounds are known.

There's no range checking for FFI arrays. It would be pointless,
because you can e.g. index a pointer, which contains no information
on the original array bounds.

> Otherwise we would need to store this number somewhere close the
> the cdata too. And when talking about matrices we need also
> store size of all dimensions.

Use a variable-length struct (VLS), with the array as the last
element. Store the dimensions in the struct elements.

--Mike