synchronized lists

Roman Suzi rnd at onego.ru
Fri Jul 20 04:21:25 EDT 2001


On Fri, 20 Jul 2001, Andreas Kremer wrote:

> Hi,
> 
> i have the following design problem:
> 
> in different classes i have lists which consist of elements pointing to
> instances of other classes with lists. What i need to acchieve is that if an
> instance of one class is pointing towards another instance, the latter needs
> a pointer to the former in its list, too, to know who is pointing at it. The
> result would be at least two lists in each instance, one with pointers
> outwards to other instances, the other with pointer to instances which point
> to this instance.
> 
> I was thinking about a superclass of  synchronized lists, but that design
> did not look "nice". Also a connector doesnt seem to be the best idea. Has
> anybody an idea about how to acchieve this goal?
> 
> Thanks in advance, Andreas.

The better idea is to have a container class which could register
contectedness information in a special hash and provide ways to request
who is connected with who. (This could be as you said a superclass, but
maybe you can just have it as attribute.)

Making pointers to and from is messy and a usual source of cyclic
references. Combined with using __del__, this will result in "memory
leaks", IIRC.



Sincerely yours, Roman A.Suzi
-- 
 - Petrozavodsk - Karelia - Russia - mailto:rnd at onego.ru -
 





More information about the Python-list mailing list