I've been reading about slots, and since this seems to be a serious memory issue that's somewhat different from C++ and Java that I'm familiar with, I just wanted to know the right way to instantiate classes of other libraries in my class.
Example: This is how I'm currently doing it (roughly):
import pymunk
from pymunk import Vec2d
class RobotBody(object):
chassisXY = Vec2d(0, 0)
chassisMass = 10
chassis_b = [] # chassis body
chassis_s = [] # chassis shape
def __init__(self, chassisCenterPosition):
self.chassisXY = chassisCenterPosition
self.chassis_b = pymunk.Body(self.chassisMass, pymunk.moment_for_box(self.chassisMass, (100, 100)))
self.chassis_b.position = self.chassisXY
self.chassis_shape = pymunk.Poly.create_box(self.chassis_b, (100, 100))
rb = RobotBody(Vec2d(600, 100))
However, is the right way to instantiate chassis_b
and chassis_s
like this?
chassis_b = pymunk.Body() # chassis body
chassis_s = pymunk.Poly() # chassis shape
The member variables are going to get replaced by other Body
and Poly
objects during __init__
anyway, so is it worth instantiating them with a class instance or is there a way to instantiate it as null
, which would hopefully save memory/processing-time? I tried using pass
, but it didn't seem to work in this case. I have the same question for Vec2d
or any other 3rd party library class that is used.
It'd also be nice if I could have some info/pointers on how this memory management happens in Python.
UPDATE: I just found that it isn't possible to instantiate chassis_b = pymunk.Body()
because Body()
needs 3 parameters passed to it. Still, my question remains the same.