I am creating a geometry library in C# and I will need the following immutable types:
Vector2f(2floats – 8 bytes)Vector2d(2doubles – 16 bytes)Vector3f(3floats – 12 bytes)Vector3d(3doubles – 24 bytes)Vector4f(4floats – 16 bytes)Vector4d(4doubles – 32 bytes)
I am trying to determine whether to make them structs or classes. MSDN suggests only using a struct if the size if going to be no greater than 16 bytes. That reference seems to be from 2005. Is 16 bytes still the max suggested size?
I am sure that using structs for the float vectors would be more efficient than using a class, but what should I do about the double vectors? Should I make them structs also to be consistent, or should I make them classes?
Updated:
Looks like the everyone agrees they should be structs. Thanks for the great answers.
Microsoft’s XNA Framework uses structures for its Vector2/3/4 data types. These contain fields of type
float. I don’t see anything wrong with doing the same; using fields of typedoubleshouldn’t make a big difference.