Struct vs Class quiz
In the previous example, why the class executable is significantly faster?
Classes in D are implemented more efficiently | When a variable is pass by value, we create a copy of the variable and it’s content everytime we use it in a function. So, for structs we are creating a million copies, while for classes only one, hence the implementation with classes is faster. | |
Structs are stored on the stack data segment, which is slower | When a variable is pass by value, we create a copy of the variable and it’s content everytime we use it in a function. So, for structs we are creating a million copies, while for classes only one, hence the implementation with classes is faster. | |
Structs are value types, every time we call | Correct | |
Classes have faster acces to their data | When a variable is pass by value, we create a copy of the variable and it’s content everytime we use it in a function. So, for structs we are creating a million copies, while for classes only one, hence the implementation with classes is faster. |