AA strange behavior

Sean Kelly sean at f4.ca
Tue Jun 13 09:08:13 PDT 2006


Oskar Linde wrote:
> Georg Wrede skrev:
>>
>>
>> Carlos Santander wrote:
>>> Oskar Linde escribió:
>>>> There are other ways. For instance:
>>>>
>>>> foreach(key;aa.keys)
>>>>     aa.remove(key);
>>>>
>>>> or faster (as you seem to want to delete all elements), but ugly, 
>>>> hackish and undocumented:
>>>>
>>>> struct BB { void *[] buckets; size_t nodes; }
>>>>
>>>> ....
>>>>
>>>> (cast(BB*)&aa).buckets = null;
>>>> (cast(BB*)&aa).nodes = 0;
>>>>
>>>> (A wish would be for the above to be implemented as aa.clear())
>>>>
>>> I think this would be a useful addition to AAs. It has been proposed 
>>> more than once, I don't know why Walter hasn't added it yet.
>>>
>>>> Or if you just want to forget about your current aa instance:
>>>>
>>>> aa = null;
>>
>> Hmm.
>>
>> Of course reuse is good. Greenpeace Likes Reuse(tm)!
>>
>> But is there really enough merit in reusing a hash, as compared with 
>> using a new one? I mean, in both cases we are effectively abandoning 
>> the buckets and the nodes to GC. -- To reuse /them/ would give 
>> savings, but I'm unable to believe it's worth the effort, or even 
>> smart at all.
> 
> The AA is a reference type. There can be many references to the same AA. 
> aa = null will only change one reference, while the proposed aa.clear() 
> would clear the actual AA that all references refer to. There is a 
> significant semantic difference.

What about "delete aa"?  Or was the goal to keep the buckets around and 
just toss the data?


Sean



More information about the Digitalmars-d-learn mailing list