Having the pointer (which doesn''t use much memory (32 bits I think?)) in every class is a nice way to have quick access to it within the class''s private functions and it prevents having to pass the pointer (except in the constructor). I like to do it this way for that reason. On the other hand, if 100 MB of memory usage (you are talking about system memory right?) is too much for the requirements you want to meet, then pass it through functions...at the expense of a little larger executable. You may be able to optimize things a little more too. For instance, instead of putting the pointer in every single class, put it in the parent class (like a manager of some type), then from the child classes, call Parent->Device, where you saved the Parent of the class.
class cWindow
{
public:
LPDIRECT3DDEVICE9 pd3dDevice;
cWindow(LPDIRECT3DDEVICE9 fp3dDevice);
};
class cWindowComponent
{
private:
pfUpdateVertices(void);
cWindow *pParent;
public:
cWindowComponent(cWindow *fpParent);
};
cWindowComponent:
fUpdateVertices(void)
{
// Do whatever with pParent->p3dDevice.
}
This way, you could make 1 window with 20 components, but only store the device in the 1 window. You could take it a step further by storing the device in the cWindowContainer class, then calling pParent->Parent(this one would have to be public)->p3dDevice; for all windows and all components in every window. It would generate a slightly small loss of cpu (are we counting nanoseconds? Yes we are...we make games.
) but it would reduce your memory overhead.
Chris