Data Type Overflow

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

Hi All,

I coding am application that needs to be VERY time and space
efficient. I have a class like:

class A{

ushort myNum;
.....
}

which contains a number datatype.

I will have thousands of instances of class A and for the vast
majority of instances, the myNum value will fit in a ushort data type
(<65535), but for a few it will be greater.

How can I get around this in an efficient manner?

* Use an object reference and convert to a bigger datatype in the
event of an overflow?

cheers,
Steve.
 
Just use an int, the ushort will be aligned to 32bits anyway. But if you really need to be space efficient this is not the best way
because creating a class will take up at least 8 bytes per instance. If you used an array of shorts this would be only 2 bytes.
 
In the cases where the value will not fit in a ushort, what action do you
take?

--
Jared Parsons [MSFT]
(e-mail address removed)
This posting is provided "AS IS" with no warranties, and confers no rights.
OR if you wish to include a script sample in your post please add "Use of
included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm"
 
Back
Top