Where does the compiler store methods for C++ classes?
- by Mashmagar
This is more a curiosity than anything else...
Suppose I have a C++ class Kitty as follows:
class Kitty
{
void Meow()
{
//Do stuff
}
}
Does the compiler place the code for Meow() in every instance of Kitty?
Obviously repeating the same code everywhere requires more memory. But on the other hand, branching to a relative location in nearby memory requires fewer assembly instructions than branching to an absolute location in memory on modern processors, so this is potentially faster.
I suppose this is an implementation detail, so different compilers may perform differently.
Keep in mind, I'm not considering static or virtual methods here.