Memory allocation can be time consuming. However, I believe that a cleaner, more obvious measurement of resource consumption will take up space, not creation time.
As you have already stated about yourself, this is the case when methods, static or not, take up memory space only once. The this link is just a hidden parameter that is sent from the caller to the called code in the same way as any other parameter, and in the end all methods are just simple functions (or routines).
In a simplified way to set it, as well as all static fields. Do not think about the properties. These are just high-level wrappers for methods that are at the end of an access field.
Instance fields take up space per instance. But there are other things, such as runtime information, which also stands out.
In short, your assumption is correct.
EDIT
As well as a summary:
- If by “large class” you mean a class that defines many methods, then no, the instantiation time will not be affected.
- On the other hand, if by this term you mean a class that defines many fields of an instance, then yes, the creation time will be affected.
Although this is not my happy place (I know almost nothing about how good ol ' malloc really manages to defragment memory), thinking that allocating a large amount of memory will take longer, strange, I can’t push my finger, as if to say that
"adding the numbers 1024 and 2048 takes a little longer than adding the numbers 3 and 4"
(provided that all 4 numbers are stored in variables of the same number type).
So, I'm more worried about memory consumption. I am sure that time is also affected, but it can be logarithmic.
Eduard dumitru
source share