Class Array Functions vs. Static Functions [Memory]

Basically, I had a question about the memory consumption of functions in a class array.

If there is an array of a class with a big function body does that function get rewritten with each new copy of the class in the array or does it just create a reference to the class structure and use some sort of scope?

For Example:
Player ** players;
player = new Player*[2000];

This created 2000 Classes. My question is with those 2000 classes, do I have 2000 individual classes or 2000 references in memory to this class, but each different copy has a different scope.

Really, I'm asking is, is it logical to convert this class to just have variables and make each function in it static to conserve memory?

Conversion:
int getSomething()
Converts to:
static int getSomething(Player p)
Last edited on
Functions do not exist in the memory for the class you allocate with new. The only possible exception is when you have virtual functions, in which case each class you create has an extra 'vtable' pointer that points to the virtual functions.
Functions do not exist in the memory for the class you allocate with new. The only possible exception is when you have virtual functions, in which case each class you create has an extra 'vtable' pointer that points to the virtual functions.

Thanks so much. I had a hard time to get people to understand my question.
This might be an interesting read as well. The this pointer allows non-static member functions to be called on specific objects but it is not part of the object's memory. static member functions are not generated with this implicit this parameter, therefore static member functions can only read/write static data members unless you manually pass an object pointer to them.
http://www.codeguru.com/forum/showthread.php?t=343480
Topic archived. No new replies allowed.