Is there a speed diff b/w static and/or global?
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..
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement