Advertisement Jump to content


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


Globals (bad) and structures

This topic is 6120 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

Ok, I''ve herd that globals are bad in a program. Lets assume they are. If I re-locate all my globals into a structure or class, will this be a good thing, or just the same this as having globals?? (cause the struct is still global). Whats the difference between global class'' and global data types?? Denis Lamarche

Share this post

Link to post
Share on other sites
The problem with global data is that any function can mess with it. In smaller programs, it''s not such a problem, but in larger problem is can become difficult to track, and downright unmanageable. It''s always safer to pass the data to another function by reference, rather than make it global.

Global data has it''s advantages, though. For games, where speed is an issue, global data is faster, because passing by reference requires entries into the stack. It''s a lot of overhead that you can do without. By deviding the global namespace in sections using namespaces, your global data can become more manageable in larger programs, because only code blocks declared to use a namespace can use variables declared within that namespace.

Then again, I''m kind of a noob and you should wait to hear a second opinion.

People get ready.
I''m ready to play.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!