I am using python to implement an application. I have following classes:
class A():
def __init__(self):
self._B_list=[] # objects of B class will be appended as the application run
b = B(self) # I use A as initial parameter of B
self._B_list.append(b)
class B()
def __init__(self, A_object):
self._parent = A_object # Here I save the pointer of upper layer class object
As you can see from above, class A
has a list of objects of class B
. And B
will record its upper layer object. The reason I do this is because there is a big data container (20 MB) in class A
, and it should be shared by all the class B
objects in its list.
I think the way I showed above is memory effective. But since I've never been formally traind to code Python, I am not very sure about this. So may I have you opinion? Any comments are welcome.
Thanks.