lua-users home
lua-l archive

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

> Am 02.10.2015 um 14:49 schrieb Roberto Ierusalimschy <>:
>> A similar feature that has been asked before is to do that for
>> strings, for example to use read-only memory on low-RAM platforms. I
>> believe eLua has such a feature, and IIRC Roberto mentioned it (in a
>> recent workshop video) as a potential future feature for Lua. If that
>> ever makes it into Lua for strings, it would be nice to have the same
>> option for bytecode. But on the other hand, contrary to strings, the
>> runtime memory layout of the function prototypes may not be exactly
>> that of the serialized bytecode.
> We could reuse only the bytecode array (and lineinfo array, if present).
> This is usually the bulk in large functions. (Currently Lua copies
> everything into the interpreter. It never keeps pointers to outside
> memory.)

I am experimenting with different ways to execute Lua code.  The current behavior of copying everything into the interpreter of course make sense, since normally you load the code from an external file using either open(), read(), 
lua_loadXXX(), close() or, what we do most of time, mmap(), lua_loadXXX(), munmap().  So after munmap() the byte code is no longer available.

Now I wrote a script that will convert bytecode to a C character array and emit this with some glue code to a C compiler (clang in the case of the example).  This means that the bytecode sits there, directly in the binary, as a static character array that will never go away and which never is freed.  So in this case I am wasting memory, because I keep two copies of the bytecode in memory.  So with this usage pattern (and whether it is a sane one is a different question) it would be desireable to not copy everything into the interpreter, but just use it.

I atteched the script, in case anyone is interested.

Attachment: luacc.lua
Description: Binary data