Jump to content
  • Advertisement


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


Is there a speed diff b/w static and/or global?

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

I am currently using static members to access game data between classes, but I was wondering if using this takes a extra couple of cycles. I know that everytime you access member data the computer has to access the this ptr everytime (I think anyways..) So does extern have any benifits? Thanks in advance..

Share this post

Link to post
Share on other sites
I''m fairly sure that there''s no penalty for accessing a static member variable. The reason that accessing normal member variables requires the "this" pointer is that the member variables exist for each instance of the class. Thus, if you have 4 instances of class C, and class C has member variable m_nCount, then there are 4 variables named m_nCount around, each associated with an instance of the class (ie. the "this" pointer).
However, static variables do NOT exist on a per-instance basis -- they are shared between all instances of the class and live for the lifetime of the program. They are basically global variables that can only be referenced from code within whatever class they are defined in. (Unless you declare them public, in which case anyone can write to them at any time the same as a global variable).

Hope this helps.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!