Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.



This topic is 6698 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello fellow spodlings. I was wondering whether globals are that much faster than any other method which should proffer me to use them. I have quite a laughingly stupid method at the moment; let me describe it. I have a class, CBitmapImage - when it an instance is spawned I pass to it a pointer to CDirectXEngine, inside which is encapsulated all the horrors re: bits and masks and main surfaces and flipping etc. So every frame, when the Bitmap renders, it calls pDirectXEngine->GetWorkingSurface(). I was wondering whether perhaps having a global pointer to the surface is better in any way, shape, or form? r.

Share this post

Link to post
Share on other sites

It is personal wheter one method is better than the other... I personally have used a method just about like yours for 3 years or so... I think it is fast... readable and understandable, but some may disagree. I can tell you one major disadvantage about globals however... Have you ever created a program of say 100,000 lines.. then you will know that many globals is not the way to do it. (although some swear at globals)

Whenever I need to use globals... I prefix the variables with "g_" so that I will know everywhere in the program wheter a variable is local or global...


int g_Int = 2;

void main(void)
int Int = 1;

printf("Global int %u\n", g_Int);
printf("Local int %u\n", Int);


Please do not tell me that the return is not neccessary... I know... but I always add it... even for void functions

Greetings Dark

Share this post

Link to post
Share on other sites
Yeh I thought so. However consider this situation: The CConsole class is relying on a CBitmapFont class which is relying on a CBitmapImage class. So passing pointers around instead of using globals might be better in that sense. But then at the lowest level, when it comes to drawing the things, CBitmapImage needs to know things such as screen_height, screen_width, RBitShift for alpha blendimajigy etc...These are either retrieved every frame for every obj drawn or multiple instances of these are kept in every class..or as I see globals would eliminate this unefficiency?
Or am I being obtuse?

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!