[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: "clear" array
- From: Nick Gammon <nick@...>
- Date: Fri, 29 Sep 2006 12:52:42 +1000
On 29/09/2006, at 10:56 AM, Wesley Smith wrote:
I'm trying to "clear" an array after a loop is run and reuse it again
on the next iteration. By "clear" I mean that I wat #array to be 0.
One approach which was discussed earlier is to remove all entries,
like this:
for k in pairs (t) do
t [k] = nil
end -- for
After that the table is empty, and getn returns 0.
This has the advantage that if you have other references to the table
(you may not) then they all point to the same, emptied, table. Also,
for small tables it may be faster than creating a new table. For
larger tables, and if you don't have references to the table
anywhere, making a new one is probably faster.
- Nick