G
Guest
General Info:
A struct is stored on the stack and a class on the heap.
A struct is a value type while a class is a reference type.
Question:
What if a struct contains a string property(variable). The string would
be a reference type being contained in a value type. Would this filter
up and cause the stack to now be a reference type placed on the heap
or would it still be on the stack with a pointer used internally to point
to a preallocated string object on the heap?
The reason for the question is because almost all examples related to
stacks and discussing the speed benefits never show anything in the
stack other than value types (which a internally structs themselves like int).
I am creating a large binary tree and currently use classes to implement it.
There are no problems with the code, but if I could see a major performance
gain by switching the classes to structs I would do it.
What do you think?
-Greg
A struct is stored on the stack and a class on the heap.
A struct is a value type while a class is a reference type.
Question:
What if a struct contains a string property(variable). The string would
be a reference type being contained in a value type. Would this filter
up and cause the stack to now be a reference type placed on the heap
or would it still be on the stack with a pointer used internally to point
to a preallocated string object on the heap?
The reason for the question is because almost all examples related to
stacks and discussing the speed benefits never show anything in the
stack other than value types (which a internally structs themselves like int).
I am creating a large binary tree and currently use classes to implement it.
There are no problems with the code, but if I could see a major performance
gain by switching the classes to structs I would do it.
What do you think?
-Greg