Big class and pointer to that.

This is a discussion on Big class and pointer to that. within the C++ Programming forums, part of the General Programming Boards category; As my program is getting larger, my class is getting larger too, this is what i now have: Code: class ...

  1. #1
    Unregistered
    Guest

    Big class and pointer to that.

    As my program is getting larger, my class is getting larger too, this is what i now have:
    Code:
    class GlobalDef
    {
    public:
    	//global variables:
    	///////////////////
    	//General DirectX8 variables
    	struct GeneralDX
    	{
    		IDirect3D8				*d3d8;
    		IDirect3DDevice8		*device8;
    		D3DDISPLAYMODE			dmode;
    		D3DPRESENT_PARAMETERS	e_present;
    		D3DCAPS8				Caps;
    		//-----------------------------
    		D3DDEVTYPE				rastermode;
    		DWORD					vertexmode;
    		D3DVIEWPORT8			viewport;
    		float					aspect;
    		//tris/sec specific.
    		
    	
    	}GeneralDX;
    	//Time and FPS
    	struct TimeAndFPS
    	{
    		INT64 nFreq;
    		INT64 lTickCount;
    		INT64 cTickCount;
    		int mFrameRate;
    		int mFrameCount;
    		bool mInited;
    		
    		//timeelapsed related
    		float timeStart;
    		float lastTime;
    		UINT64 tickspsec;
    		
    		
    	}TimeAndFPS;
    	//Matrices
    	struct Matrices	
    	{
    		D3DXMATRIX				matWorld;
    		D3DXMATRIX				matView;
    		D3DXMATRIX				matProj;
    	}Matrices;
    	//Misc
    	struct Misc
    	{
    		//application
    		RenderTechApplication	EnApp;
    		//capabilities
    		HWCaps					dcaps;
    		//zbuffer struct
    		ZModes					zd;
    		DWORD					ClearColor;
    		RECT					winRect;
    		bool					worldcull;
    		bool					ShowErrors;
    		char*					errstr;
    	}Misc;
    	
    	struct Objects
    	{
    		//Text related goes here
    		vector<FontMan>		Fonts;
    		UINT				fontnum;
    		RECT				textRect;
    		
    	}Objects;
    	//window structure
    	struct WindowStruct
    	{
    		HWND			hWnd;
    		HINSTANCE		hInst;
    		int				iWidth;
    		int				iHeight;
    		char*			clsName;
    	}WindowStruct;
    	
    	struct Input
    	{
    		//keyboard
    		LPDIRECTINPUT8			input8;
    		LPDIRECTINPUTDEVICE8	inpdev8;
    		char					KeyBuf[256];
    
    		//mouse
    		LPDIRECTINPUTDEVICE8	mousedev8;
    		//mouse state
    		DIMOUSESTATE2			MState;
    		DIDEVICEOBJECTDATA		data;
    		//used to check if devices are acquired.
    		bool kaq;
    		bool maq;
    	}Input;
    	
    };
    There is a pointer to that class GlobalDef* g;

    My question now is, how much overhead there is? Could it be better to use global variables instead of this huge class, which will grow twice as that in the future?

  2. #2
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    Dunno what you're worring about? It aint big at all.

    Just declare a static instance of your class. In this case, your class acts as nothing more than a namespace for your global variables.

  3. #3
    Unregistered
    Guest
    I shouldnt declare a pointer of it? What would be the difference between a pointer to class and just an instance to it? This class will not (possibly not..) have any functions, only variables.

  4. #4
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    > I shouldnt declare a pointer of it?

    Let me ask, would you do this:

    int* a = new int;

    or just:

    int a;

    I suppose the only thing you need to be careful of is the actual size of your class. I notice that many of the data items in it are pointers to other data (hence there are pointers of just 4 bytes).

    Do a sizeof on your class. If we are talking about KB's or more make an instance on the heap (as opposed to the stack) by calling new. Then use a static pointer to point to that instance.

    i.e.

    static GlobalDef* def = new GlobalDef

    Otherwise, just declare a static instance in a header file and stop worrying. Like so:

    static GlobalDef def;
    OS: Windows XP
    Compilers: MinGW (Code::Blocks), BCB 5

    BigAngryDog.com

  5. #5
    Unregistered
    Guest
    Ok, thank you very much
    I was worrying because the class will get very huge.
    Cya

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with FIFO QUEUE
    By jackfraust in forum C++ Programming
    Replies: 23
    Last Post: 04-03-2009, 09:17 AM
  2. Smart pointer class
    By Elysia in forum C++ Programming
    Replies: 63
    Last Post: 11-03-2007, 08:05 AM
  3. Replies: 25
    Last Post: 10-29-2007, 05:08 PM
  4. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 03:33 PM
  5. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21