Are there any performance penalties when I use multiple nested structures/classes (kinda like using muti dimension heap arrays) or is it just an organizational feature of the language to make it easier to keep track of data and the compiler doesn't actually see any difference?
Thanks
Not really. Classes/structs are just defining offsets into memory, so if you have a class within a class within a class, the compiler just adds up the offsets.
Performance comes into play once you have pointers (each pointer dereference is a memory read and potential L2 cache miss) or virtual functions (very bad, especially on older CPUs).
EDIT: One thing I should note though - if you're developing an application where performance is not absolutely crucial, focus on good class design rather than performance. While things like L2 cache misses make a big difference when you're writing something that needs to run at 60fps, it is of little relevance in a normal desktop application.
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