swarm-support
[Top][All Lists]
Advanced

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

Drop related problems (SimpleExperBug and Map)


From: Roger M. Burkhart
Subject: Drop related problems (SimpleExperBug and Map)
Date: Thu, 12 Jun 1997 16:31:59 -0500

> On a related note, I would very much like a response to a question
> raised the other day on how you drop all pointers _AND_ keys from a Map
> - from what I can glean from the documentation it is not
> enought to say:
>
>                [aMap removeAll];
>
> because that will not remove the keys. The -removeKey message in
> KeyedCollection seems to be meant for removing the object associated
> with a key, not the key itself.

removeKey: removes the entry in a Map that has a particular key, but does
nothing else with the id pointer value used as the key.  So it doesn't
drop the key, but then remove of a member of a collection doesn't drop the
member only; it only removes the member from some position in a collection.
The same objects can be used as keys or members of multiple collections.

removeAll is actually enough to remove all member and key pointers from
a Map.  It's just that removing the member or key pointers from a collection
doesn't automatically drop the object pointed to; it only removes the
pointers that reference the object from the collection.  If you
removeAll on a List, that doesn't drop the members of the list; it only
removes all the entries in the list that point to these members.  In the
case of keys in a map, it's not even guaranteed that these are objects;
using casting we often use other data types as keys of a map, such as the
timeval_t keys of a Schedule.  So the operations on a collection generally
make no assumption about the pointers the collection contains, including
whether they point to valid objects.

> I have been using Maps extensively and don't feel to great about
> choosing between bleeding memory or repeatedly dropping and creating new
> Map instances.                                                                
>  
After removeAll, a collection is guaranteed to hold zero members (getCount
returns zero) but to still be valid with the same object id for the
addition of new members.  This is a little more efficient than just
dropping the original collection and creating a new one, but not by much,
and it also saves having to reset any id's that pointed to the old
collection.

If you also need to drop objects that were created specifically to be used
as keys or members of the collection, you should first traverse the whole
collection using an index, getting the key and member objects at each
index position and dropping them.  If you're about to drop or removeAll
on the collection, you actually don't even need to worry about any dangling
references to the objects just dropped, since the remove on each collection
entry won't check validity of the pointers remaining. 

-Roger


                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.
                  ==================================


reply via email to

[Prev in Thread] Current Thread [Next in Thread]