Re: Function to force table to shrink?
Roberto Ierusalimschy <[email protected]>
| Newsgroups | gmane.comp.lang.lua.general |
|---|---|
| Message-ID | <[email protected]> |
> I was under the impression that PUC Lua does actually shrink tables
> sometimes, at least the hash part, but I will check the sources and test
> again (unless the authors would like to answer off the top of their heads
> ;)) so I can make some reasonable statements about what is likely to happen
> and when.
A table will shrink if you keep adding keys to it. Adding keys will
eventually force a rehash; if, at that point, the table needs less space
than it was using, it shrinks.
------------------------------------------------
local a = {}
for i = 1, 1e5 do a[i] = true end
print(collectgarbage"count" * 1024)
for i = 1, 1e5 do a[i] = nil end
print(collectgarbage"count" * 1024)
a.x = true
print(collectgarbage"count" * 1024)
------------------------------------------------
-- Roberto
--
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/20260202190458.GB10552%40arraial.inf.puc-rio.br.