lua-users home
lua-l archive

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


Dimiter malkia Stanev wrote:
> Is ffi.alloca() possible with luajit, (taking the same arguments as
> ffi.new) - e.g. instead of allocating on the heap, to allocate on
> the stack?

On which stack? And what's the scope and the lifetime? A trace
compiler has no concept of functions that would lend themselves to
an implicit scope (at least none that would also be useful for a
programmer).

A trace could certainly allocate something in the machine stack.
But functions are rarely compiled in their entirety into a single
trace. What happens when the trace exits? When is it ok to delete
the allocation? When does it have to be copied to a heap object?
What happens if the pointer changes as a result of this?

This is going to be awfully complex. Allocation sinking has
similar benefits, but should be easier to implement. And a faster
allocator + faster GC (LJ 2.1) ought to take care of the rest.

> I already have workaround for overallocating arguments, by simply
> keeping "global" copies, either outside, or as closures.

Well, the Java guys have been doing this for years. Recent JVMs do
escape analysis. But from what I hear, this is not such a big win,
except for trivial examples.

--Mike