lua-users home
lua-l archive

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

Shmuel Zeigerman wrote:
> Mike Pall wrote:
>> If you're storing all your userdatas in the array part, a simple
>> ' = nil' triggers the shrinking. If you'r storing them in
>> the hash part, a 't[1] = nil' will do.
> My userdatas are keys in a weak keyed table. I've just tried your recipe in 
> my application, both with and with t[1]=nil -- it didn't help.

Ooops, the 't[1] = nil' advice was wrong. This doesn't force
creation of the array part (which would trigger resizing). :-(

The only way then is to add lots of dummy keys which have their
primary location in the array part, delete them again, and then
cause another resize:

  for i=1,1e6 do t[i] = true end -- Adjust the 1e6 as needed.
  for i=1,1e6 do t[i] = nil end = nil

But maybe it's easier to drop the table and replace it with a
fresh one? (copy remaining elements as needed)