lua-users home
lua-l archive

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


Can you give an example how you do this? Do you avoid this "stack
de-allocate" in Lua code or in C code?

... just for interest, sorry, I do not really understand what you mean
by "stack re-allocate" / "stack de-allocate", but it sounds somehow
interesting possibility... .

On Tue, Jan 11, 2022 at 11:39 AM Julien Cugnière
<julien.cugniere@gmail.com> wrote:
>
> Le lun. 10 janv. 2022 à 12:53, Xmilia Hermit <xmilia.hermit@gmail.com> a écrit :
> > Francisco Olarte wrote:
> > >> This might be a problem for the SSO since it would need to create a heap
> > >> string whenever a C function tries to get a pointer to the string since
> > >> it could be moved to a different stack index and the pointer still needs
> > >> to be valid.
> > > It is, a show stopper for me. Thanks.
> >
> > I did think a bit more about this problem. It could be solved by a
> > second "stack".
>
> 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.
>
> Julien Cugnière