Jump to content
  • Advertisement
Sign in to follow this  
Mercury Filter

Globals usage in tutorials and elsewhere.

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


Globals are problematic when you may have issues of naming, multiple simultaneous accesses and manipulation, variables with a high load of usage in general (globals aren't as fast as a local variable, depending on your compiler), harder to keep track (need a namespace). If those problems with the global variables don't affect you for some reason, they may be useful sometimes.

I may have asked the question in a bit unclear fashion, but one of the things that I was interested in was things such as the stated speed difference between local and global variables. The impression that I have gotten from responses is that a lot of the matter lies with what you are writing the program for.

If I were to attempt to delve into the details of why these differences occur, would some of this be the memory system? I feel like it is a rough way to ask the question; would it be more specifically the way that the specific language deals with handling memory?

I am more than happy to use google myself, but if anyone is familiar with any good resources off the top of their heads (I don't consider it anyone's responsibility to find it for me, but if you are already familiar with something it would certainly make it easier, lol), that would be a good starting point, it would be appreciated.

Share this post


Link to post
Share on other sites
Advertisement
No, it's to do with 'computer architecture' (specifically, the CPU cache and 'locality of reference') rather than language.

The other issue I mention was aliasing, which is something that compilers have to care about when optimizing.
http://en.m.wikipedia.org/wiki/Aliasing_(computing)

These things don't mean than "globals are slow" -- members or arguments can suffer from the same issues.
You've got to do a case by case analysis on any piece of code to figure out if/why it's slow, which isn't really a for beginners topic ;)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net 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!