I'm wondering how static member variables are typically implemented in languages like C++ and if their use affects the size of instantiated objects.
I know that a static members are shared by all instances of that class, but how is it shared? If it affects object size, would having 10 static variables add more size than 1?
I'm asking because I can think of two ways it might be implemented:
- adding a pointer to static data to each object similar to the way some implementations add a pointer to the virtual function table
- the static data is just referenced directly like a global variable with the offset being resolved by the linker / loader