lua-users home
lua-l archive

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


On Thu, Jun 4, 2015 at 3:28 PM, Paul K <paul@zerobrane.com> wrote:
> I think I read somewhere recently (here? the wiki?) that it will resize the array section not after you nil-out trailing entries, but when you next assign a non-nil value to an array index; it will grow or shrink it as appropriate

As far as I understand, the table is rehashed when there is no space
in the hash part of the table to insert a new key. The logic is in
luaH_newkey (ltable.c) and rehash is called when "main position is
taken?" and "cannot find a free place?" are both true.

I'm not sure this applies, since Dirk was asking about sequences and I was specifically talking about the array part. It might help if I clarify that I meant if you've got a sequence that lives in the array part with n = 2^k elements, and set entries j, j+1 ... n to nil, it won't trigger the garbage collector or release memory. But if you then assign an non-nil value to index j, it will resize (compact) the array part to fit.

I'm not sure this is actually true, or for what values of j, but I'm pretty sure I read this recently and am curious about confirmation or outright contradiction, since I'm not seeing that happen in 5.3.

--
Brigham Toskin