[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Avoiding string duplication
- From: Rodrigo Azevedo <rodrigoams@...>
- Date: Wed, 6 Nov 2019 20:59:47 -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 assumes 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?
In fact, all 'implementation-dependent', as well as 'undefined', behaviors could be rethought, aiming a 'well-defined' language.