lua-users home
lua-l archive

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


On Apr 12, 2014, at 7:07 PM, Ross Bencina <rossb-lists@audiomulch.com> wrote:
> 
> I wonder what it would take to provide an API for zero-copy "injectable" immutable strings.
> 
> lua_injectstring()
> 
> An API where the client C code can do the work of allocating the string buffer (presumably with some particular sized header for VM use). The client would then add the string to the VM state with "inject". This has the effect of handing off responsibility for deallocating the memory to the VM/GC.
> 
> The same type of injection would be useful for userdata.
> 
> It would be even more useful if calls to the deallocate function indicated that such memory was of this "injected" type (using a flag), or called a separate deallocate function for injected memory.
> 
> Ross.
> 

This is the “ownership transfer” model used in some other scripting APIs, and while i’ve seen it help in a few cases with performance it mostly just contributes to nasty memory leaks and related problems. As I said earlier, in most cases the extra copy overhead is just not that significant. We marshal a LOT of data among Lua states, and the copy overhead has never been an issue, either on high-end x86 systems or tiny battery powered ARM systems.

—Tim