|
Hi! On 22.03.2012 23:27, Roberto Ierusalimschy wrote:
As I think I've mentioned previously, 'd like to be able to mmap a big file and add it as some sort of string to Lua without copying the contents at all.]Yes, you mentioned that. Also, people in embedded systems seem interested in avoiding long constant strings being copied into RAM. There are other cases. To get there, stop internalizing is a first step.
I'm not sure of that. You could still do hashing and interning for external strings and always return the first occurrence of a string. All you need is a flag for Lua to not touch the memory buffer during garbage collection (which you would need anyway). Mmapped files are a problem though (unless you don't use them in table keys), because the contents could change at any moment. Also mmapped files typically aren't zero-terminated ... (which is no problem for Lua, but maybe for the Lua C API user).
As far as the interning cost is concerned: what about lazy interning for all strings independent of the length? Just do the interning when they are first used as part of == (and have the same length) or in (new-)index operations. I guess there are many short temporary strings that are never used as table keys and probably garbage-collected right away.
-- Roberto
Philipp