Re: # on known length ffi array

  • From: Mike Pall <mike-1206@xxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Mon, 11 Jun 2012 01:06:48 +0200

Justin Cormack wrote:
> Would it be possible for the # operator to work on known length C arrays?
> (not VLAs or cast pointers obviously). eg if I have a = ffi.new("int[8]")
> then #a == 8.

The problem is that #a would be most interesting for VLAs.
However, as I've previously mentioned, getting the size of VLAs is
going to be expensive with the new GC in 2.1. So I wouldn't want
to introduce a feature in 2.0 that wouldn't be very useful later.

Ok, so you'll need to pass around the length, too. But that adds
some flexibility, too. Now you can pass a pointer and not just an
array. Or use interior pointers and a partial length to work on
array slices.

--Mike

Other related posts: