lua-users home
lua-l archive

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


On Fri, Dec 13, 2013 at 10:37 PM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
> 2013/12/13 Coda Highland <chighland@gmail.com>:
>
>> I believe what you've missed is a recent thread requesting a
>> table.wipe function to the C API that could wipe a table more
>> efficiently than iterating over the contents and nil'ing out every
>> entry. This appears to be a request for functionality in this proposed
>> function.
>
> It was not obvious to me during that discussion, and it is even
> less obvious now, that it is so very inefficient to do exactly that.
> In fact, I can't see how any C routine would be able to avoid
> doing it. Andrew's neat exploitation of the generic `for`:
>
>     for i in next, t do t[i]  = nil end
>
> is clear enough for me.
>

A routine using the Lua C API, no, you're right. A routine with access
to the internals? If I'm not mistaken, it'd be fairly easy to replace
the table contents with a fresh object and leave its children to be
collected on the next GC sweep since they'll have become inaccessible.

/s/ Adam