Archived

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

Trajar

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

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.
...Syzygy

Share this post


Link to post
Share on other sites