Should I Make These Vectors Classes or Structs in C#
Posted
by dewald
on Stack Overflow
See other posts from Stack Overflow
or by dewald
Published on 2010-04-18T20:25:55Z
Indexed on
2010/04/18
20:33 UTC
Read the original article
Hit count: 487
I am creating a geometry library in C# and I will need the following immutable types:
Vector2f
(2float
s - 8 bytes)Vector2d
(2double
s - 16 bytes)Vector3f
(3float
s - 12 bytes)Vector3d
(3double
s - 24 bytes)Vector4f
(4float
s - 16 bytes)Vector4d
(4double
s - 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?
© Stack Overflow or respective owner