class A (say), having all static member functions only class B(say) having only member functions
If i create 1000 instances of class A. As the class contains only static member functions, the memory do not increase even if there are 1 instance or 1000 instances.
However, for class B. If i create 1000 instances, will there be an increase of memory (even the slightest, may be a pointer for each object pointing to set of member functions) ?
If no, then how does the compiler keep tracks of member function information for a particular object ?
Will there be an increase of memory (even the slightest, may be a pointer for each object pointing to set of member functions)?
NO.
Non virtual Member functions do not contribute towards size of objects of a class.
However, presence of a virtual member function will typically increase the size of an class object.
Note that the latter is purely implementation specific detail but Since all known compilers implement the virtual mechanism using v-table and v-ptr, it is reasonable to assume that almost all compilers will show the same behavior of adding a v-ptr to every object of that polymorphic class thus increasing size of the class object by size equivalent to that of v-ptr.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With