[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Are there some potential problems if I use a self-defined memory acquirement function instead of realloc(3) in the l_alloc function?
- From: 孙世龙 sunshilong <sunshilong369@...>
- Date: Tue, 11 Aug 2020 10:44:08 +0800
Thank you for your clarification and guidance.
>Lua 5.4 has removed this restriction of "no fail when shrinking".
Why is there such a restriction for the older version?
Could you please explain that in more detail?
>Actually, the test suite in Lua has a mode that forces every
> single reallocation (growing, shrinking, or to the same size!) to move
> the block.
What are the purposes for providing this mode(i.e.
forcing every single reallocation to move the block)? For security?
When should I use this mode?
Thank you for your attention to this matter.
Best Regards.
Sunshilong
On Mon, Aug 10, 2020 at 10:36 PM Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
>
> > I think Lua relies on the behaviour that the realloc-like function
> > does not return a different pointer (copy) for shrinking an existing
> > block. Maybe that could be a problem for some allocators.
>
> Lua does not rely on that. The only assumption was that shrinking
> an existing block could not fail, but it can move the block without
> problems. Actually, the test suite in Lua has a mode that forces every
> single reallocation (growing, shrinking, or to the same size!) to move
> the block.
>
> Lua 5.4 has removed this restriction of "no fail when shrinking".
>
> -- Roberto