// Some Pseudo Code of Class Foo Class Foo { Static int FooCount; float FooVariable; Static int FooInc() {return FooCount++;} float GetFooVar() {return this.FooVariable;} } Foo MyFoo = New Foo(3.14); Foo MyFoo2 = New Foo(6.02);
We have Class Foo that has some static and normal variables. It also has static and normal methods. We instantiate this class in MyFoo with a New method and FooVariable = 3.14 and MyFoo2 with FooVariable = 6.02.
The New method also increments a Static Variable FooCounter which keeps track of how many Foo's we have running around in memory space. It does this with the Static Method FooInc(). Finally, there is a method GetFooVar() which returns the FooVariable of a specific Foo.
Now we have a memory block that contains the Foo Class along with its Static Variable FooCount = 2 and pointers to the Static Method FooInc() and normal Method GetFooVar().
There are also two memory blocks that contain the data of the Foo (one for MyFoo and another for MyFoo2). These two memory blocks also contain pointers back to the Foo Class as well as a bit more information about the Foo class. Using the class pointer and some memory offset information, they can access the GetFooVar() method. They do not have memory offset info to the FooInc() method though, because that is static and can only be called on the Foo class itself. (Probably it would be Private of course and only callable by Foo itself, but it's still Static.)
This is how I remember it, but no warantee or anything. It gets far more complex pretty quickly when you start adding things like inheritance or whatever, but I think this answers your question. Basically, one instance of Static information and methods, but each instance of the class will contain some pointer information for the class and each method it might need to call, so there will be a little extra bloat, but it should be trivial (a few bytes) compared to the size of even a single method.
By all means, please correct any errors oh compiler writing types (I don't take that class till next year).
-Lexicon
In reply to Re: OO Baggage
by Lexicon
in thread OO Baggage
by jynx
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |