[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: table.clear
- From: Ulrich Schmidt <u.sch.zw@...>
- Date: Sat, 14 Dec 2013 08:19:04 +0100
Thats exactly why i cant see the benefit from a table.clear().
I did a small test to be sure at a point i want to speak about:
-- 8x ------------------------------------------------------------
> t1={}
> t2={}
> tx={}
> t1.a=tx
> t2.a=tx
> =tx, t1.a, t2.a
table: 0x00077698 table: 0x00077698 table: 0x00077698
>-- 8x ------------------------------------------------------------
This shows me both tables t1/t2 points to the same table tx. let's think
about what happens if i would do a T2:clear():
In case the clear clear function wants to free all t2 entries
immediately, the clear function needs to check double references for
each table item of type table/function.
For me this looks like, the table.clear() needs to do the same stuff,
the _gc normally does later in background.
table.clear() could be faster, if it does not check for double
references but this narrows the usage of table.clear().
Ulrich.
Am 14.12.2013 07:55, schrieb Coda Highland:
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