Class vs Struct

I was considering if it might be better to use a struct here instead of a class given the Vector3 itself is a struct and to avoiding extra GC for each saved item (unless we reuse the same one and give up clarity).

Then I noticed the save was 159 bytes from just one transform for both types. .Net says avoid, but I was curious if this came up during course design?

I’m not sure there was a great deal of consideration as to struct vs class at this point.
Both structs and classes have their advantages and disadvantages, and have to do with how they are stored and passed, by reference or by value. Structs take memory in the stack equal to the size of the struct, while classes only contain a reference on the stack with the actual data on the heap.

For the purposes of the saving system, the choice is up to you. You can change it to a struct if you wish. If you switch to my optional Json saving system, the storage requirements will be identical.

Privacy & Terms