PDA

View Full Version : Memory vs. CPU (advice needed)



El Phantom
June 7th, 2009, 03:41 PM
Hey everybody. Recently I've been developing in a certain way that i'm not sure is wise, so I thought I would ask the guru's here for guidance. Let's say I'm developing a game with an "Enemy" class. Recently I've been making references to all the subclips in the Enemy animation and holding them in my class as variables, so for an Enemy called "Troll" i might have variables in the class saved as:

private var _walkAnimation:MovieClip;
private var _runAnimation:MovieClip;
private var _attackAnimation:MovieClip;

and then reference these whenever I need to flip between the animation states for that Enemy instead of using getChildAt() or getChildByName() to find the relevant subclip every time I wanted to reference it. I was once told saving CPU was more important than conserving memory in cases such as this, but I wanted to make sure this was true. Your thoughts?

(I call a dispose() or destroy() function when I remove enemies so the references can be Garbage Collected)

Thanks!

--EP

JonnyR
June 7th, 2009, 04:57 PM
El Phantom,

The examples that you have given above are simply refences to the Object they point to (in you case, child MovieClips) - these take up almost no memory as they are simply pointers.

Jonny.

El Phantom
June 7th, 2009, 09:57 PM
yeah, i figured that might be the case, thanks for confirming! :)