[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Avoiding string duplication
- From: Roberto Ierusalimschy <roberto@...>
- Date: Wed, 6 Nov 2019 16:05:36 -0300
According to the manual, Viacheslav is right. The "law" says that you
should not use a string pointer after you popped it from the stack.
The rationale for this is that an hypothetical garbage collector
could move strings around while collecting garbage . Lua never
used a moving (or copying) collector, so everthing always worked
"as expected". Theoretically, that could change in the future.
There are some problems for a copying collector in Lua:
- Strings in a stack cannot be moved. (More specifically, strings
in stack regions corresponding to C calls cannot be moved.)
- Userdata already assume fixed pointers to their blocks of memory.
- A copying collector works on top of raw memory, while Lua does
GC on top of an allocation function.
For all these reasons, it seems very unlikely that Lua will ever
change to a copying collector. Maybe it is time to change the manual
and make official this behavior?