lua-users home
lua-l archive

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


> I would like to see the third subtype of lua string : external string
> . The content of the string is a C pointer rather than bytes array.
> So that we can construct the long strings in O(1), it's useful when we
> want to use lua string library to manage the memory in C side.
> Or if we have many lua vm in one process, it can reduce the cost of
> message passing.

For a more generic "C pointer string subtype" in Lua, it probably would
need some system to release that external memory, e.g. by associating
the string with a callback to be called when the string is collected.

A fixed string could use a NULL callback. Such system could also allow
the buffer created by 'luaL_Buffer' to be used directly as the string
content in Lua, solving another issue mentioned previously (memory
duplication when instantiating the final string in a luaL_Buffer).

However, if we introduce a callback, it probably would also need a user
data to be passed to the callback. So, each external string would need
three pointers of overhead. That could be significant for "short" long
strings (such as in the range 40~100 bytes).


-- Roberto