I have defined a struct in my application that contains 3 integers
that maintain state information. I have a lot of these structs in
time-critical portions of my app, so they must be as fast as possible.
I also log previous values in arrays, so data size can't be ignored.
The data is such that I can implement value semantics by implementing
IComparable.CompareTo and overriding all the comparison operators as
well as Object.Equals(object o).
Since I have overriden the equality operators, the compiler keeps
suggesting I override Object.GetHashCode(). From reading the docs, I
realize GetHashCode() must return the same value for any given
instance and should be based on an immutable data member. However, my
value type is NOT immutable; I am constantly modifying values as state
changes and don't want the overhead of copying the struct every time I
need to change any of the 3 int fields.
Do I really need to be concerned about this? Can I accept the
default implementation of Object.GetHashCode() even though my struct
is not an object unless it is boxed? I really don't want to add a new
field just for HashCode support because that increases my data size by
33%!
I'm not planning on using this struct in a Hashtable or in collections
at this point, but that may happen in the future.
I would appreciate any insights into this problem!