when to use smaller integers like byte or short rather than INTEGER

when to use smaller integers like byte or short rather than INTEGER

Post by Davi » Fri, 04 Jan 2008 03:56:17


If I have a loop that has a max value of say 20 why would I not want to
define the loop counter using a BYTE or SHORT as opposed to a INTEGER.

It seems in most books or samples they define fairly small numbers as
INTEGER.

thanks, David
 
 
 

when to use smaller integers like byte or short rather than INTEGER

Post by Tom Shelto » Fri, 04 Jan 2008 08:09:24


You know it probably doesn't really matter - but, at least in the old
days using a 32-bit loop counter would give you a slightly better
performing loop :) Simply because it was the native word size of the
processor.

--
Tom Shelton

 
 
 

when to use smaller integers like byte or short rather than INTEGER

Post by Herfried K » Fri, 04 Jan 2008 10:10:33

"David" < XXXX@XXXXX.COM > schrieb:

'Integer' is IMO the natural choice. Note that bounds may change over time.
The range of 'Integer' is large enough for common scenarios. In addition,
'Integer' as a 32-bit data type is very suitable for 32-bit computers. Most
classes in the .NET Framework use 'Integer' for indices. Using other types
may require (implicit widening) type conversions.

However, 'Byte and 'Short' are not entirely useless. They are often
required in p/invoke scenarios and when reading binary data from streams
(files, network streams, etc.). Arrays of 'Byte' are typically used to
store raw binary data.

--
M S Herfried K. Wagner
M V P <URL: http://www.yqcomputer.com/ ;
V B <URL: http://www.yqcomputer.com/ ;
 
 
 

when to use smaller integers like byte or short rather than INTEGER

Post by Cor Ligthe » Fri, 04 Jan 2008 14:56:09

David,

The smaller numbers are in my idea only suitable as they are used in old
databases or DLL's.

Be aware that in a 64bit computer the Int64 is probably the best. In past
the Integer was the type that was most suitable to the in those days most
used processor. A strong loby from old Microsoft Developing tool users (in
my idea VB6) has changed that and fixed it to 32Bits for the future.

This means that in fact the Integer will become in future proabably
everytime more outdated now that it is fixed to the 32Bit computer. (It is
not very bad, it uses only (ProcessorBits/IntBits * cycles) instead of 1 and
mostly has a new computer enough cycles to hide this for you).

Cor