lua-users home
lua-l archive

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


Hi Julien:

On Tue, 11 Jan 2022 at 11:39, Julien Cugnière <julien.cugniere@gmail.com> wrote:
> If you have lots of memory, and consider that stack reallocations in
> the middle of a C function don't happen too often, a simpler (but
> somewhat dirty) solution would be that when reallocating the stack,
> you don't deallocate the old one (until the C function returns). That
> way, pointer references to short strings stay valid. This wastes a bit
> of memory holding useless stack slots in memory, but I think a well
> written C function isn't supposed to reallocate the stack more than a
> couple times. And most functions are fine with the default 20 stack
> slots.

I've give it a thought. In fact, given for my use case I have lots of
memory ( normally each state is managing phone calls, or similarly
heavy things, which have a large footprint anyway ) and do not use any
external C library and do not have too many C-LUA-C-LUA trips I could
probably just fix the stack at a large limit, pool them a bit if
needed, and abort in reallocs ( tests will catch those, they
intentionally use ludicrous sets of data which extra large stack usage
). The stuff about invalidation after insert still worries me,
although I could probably hunt and suppress it in the library. But I
was thinking on SSO for speed, all comments ( thanks everyone ) on my
query have convinced me it is not worth pursuing. I may test it
anyway, but it seems the FastString patch by Mike Pall is nearly what
I will end up doing, so first I will try to backport my code a bit to
5.1 and benchmark. I'm rereading the code paths for constant string,
which I have a lot but I've been told would not benefit much, and
trying to see how many non-constant strings I do really use in my
code. In general it seems it needs a lot more further reading before
starting coding.

Thanks.
   Francisco Olarte.