Re: Function to force table to shrink?

"'Martin Eden' via lua-l" <[email protected]>
Newsgroups gmane.comp.lang.lua.general
Message-ID <[email protected]>
On 2026-01-30 02:56, 'Lars Müller' via lua-l wrote:
> By the way, as for the discussions for how Lua could be extended: I 
> think a "table.rehash" function (name TBD) which shrinks the table 
> would not be unreasonable, and not dissimilar to existing features in 
> many other languages, like C++'s std::vector::shrink_to_fit (though 
> that shrinks a bit more aggressively than we would like in Lua). 
> LuaJIT already has a "table.clear", but this is explicitly supposed to 
> keep capacities intact.
>
> An extension of collectgarbage would feel a bit dirty.
>
> - Lars 

Hello Lars, well I disagree here.

Stock "table" module functions (concat, pack, unpack, sort, insert,
remove, move) do produce results observable in code. You can write
test for them.

Empty table slots (t['a'] = nil) are not observable. pairs() will never
return you key with nil value.

For that "dark matter" we have "shaman" function collectgarbage().
Which you also can't independently test.

It deals with mysterious "garbage". And when your code replaced
main tables it may come there and say: "Oh collectgarbage()!
We with guys just switched flow to new data tables. We kindly ask
you to free memory from the old ones."..

And so it will come there again and say similar thing regarding
table at which they discharged gatling and so now it has many holes.

-- Martin

-- 
You received this message because you are subscribed to the Google Groups "lua-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/lua-l/0463e324-b999-4cf1-8e74-bd5ac7999487%40disroot.org.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.