AA.remove in foreach && AA = new vs cleaning
Saaa
empty at needmail.com
Thu Oct 22 16:58:40 PDT 2009
Steven Schveighoffer wrote:
>> So, what is the fastest way to clean an AA?
>
> aa = null;
:(
>
> However, if you have multiple copies of the AA, this does not clear out
> the data. It merely resets the AA reference.
>
> I'd not trust your code
:)
> because it's undefined behavior. If you want to remove all the elements
> individually, copy the keys to an array, then iterate over the array
> removing each element.
This is what the dsource example does, it loops over a copy of all the keys
:)
foreach(K key; aa.keys)
aa.remove(key);
>
> Or use a real collection class, such as Tango's or dcollections' and use
> the clear() method :)
>
> -Steve
As nulling is all it takes I don't think it's that much faster :)
More information about the Digitalmars-d-learn
mailing list