When using constructor of a class to create object, it uses and stores some memory space. Creating more objects uses more space. My question is: if that class had many public type functions, logically more space will be spent, but when creating more objects of the same class that had many public type functions, will those functions will be created separately and use space more? What I want to ask is for example: class has 3 public type functions, when creating 1 object it will use something like 1*3x memory, but when creating more objects(10) will it use 10*3x memory, or just 10+3? So if I am right, when object needs to use many public type functions, and there are lots of the same objects, maybe its better to store those public functions in parent class so less memory would be spent?
Asked
Active
Viewed 38 times
1 Answers
1
Only the data members of an object use memory space. The functions/methods are always shared between all the objects. The only kind of methods that use some memory space is the virtual ones, but the space cost is usually only paid once per class type.
It does not matter if a method is defined in a parent class or a child class, they will occupy the same amount of memory as executable code. Also, the parameters are handled in the same way in both cases, so it is not faster or slower to define the method in the parent or child class.

PRouleau
- 542
- 4
- 12