Re: [ANN] LuaJIT Roadmap 2012/2013

  • From: "Robert G. Jakabosky" <bobby@xxxxxxxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Mon, 11 Jun 2012 18:09:51 -0700

On Monday 11, Mike Pall wrote:
> Adam Strzelecki wrote:
> > Just wanted to confirm whether this technique will remove heap
> > allocations for this kind of block
> > 
> > for i = 0, 1000 -- some tight loop
> > 
> >     local value = model[i] * view
> >     gl.UniformMatrix4fv(location, 1, gl.TRUE, value.gl)
> > 
> > end
> > 
> > Where model & view are 4x4 matrices of custom FFI metatype
> > having __mul operator.
> 
> Well, no, because 'value' *does* escape. There's no way for the
> compiler to know that gl.UniformMatrix4fv() doesn't store the
> 'value' pointer somewhere else.

If gl.UniformMatrix4fv() did store the value and the value wasn't also stored 
somewhere on the Lua side, then there is already a bug since the GC would free 
the value which might still be in use by the C code.

I don't see why this case should be counted as an escape for the value.  The 
compiler shouldn't care if the value is stored by gl.UniformMatrix4fv(), it is 
up to the programer to either keep a reference to the value alive or copy the 
value to manually allocated storage.

-- 
Robert G. Jakabosky

Other related posts: