>From: "Avner BenHanoch" <[EMAIL PROTECTED]>

>Which of these integral data types is best for saving calculation time on
>Palm environment? (also what about 64bit long integers)
>(I am programming with Java 2 ME for the Palm)

The 68K CPU core in the Palm devices is equally good at handling
calculations in 8, 16 or 32-bit integer sizes. 64-bit math requires a lot
more gyrations or the use of library routines since there is no native
64-bit support in the CPU.


What will get you into both extra code and extra execution time is when you
*mix* integer sizes. In this case, some extra instructions may be required
to extend or truncate values to match (not to mention possible
side-effects). For example, function arguments are always passed as 32-bit
values on the stack, regardless of whether the function prototype calls for
a Int8, Int16, or Int32. So, for example, an 8-bit argument is always either
sign-extended (Int8) or zero-extended (UInt8) before being pushed onto the
stack. In reality this adds almost nothing to the time, so I wouldn't worry
about it.

The biggest problem with using shorter integers, especially when mixing
them, are potential overflows when doing assignments. For example, if you
had:

  Int16 word_int;
  Int8 byte_int;

  word_int = 500;
  byte_int = word_int;

The assignment to "byte_int" will be done with no error posted, but the
result will be "wrong" since a signed 8-bit integer can't hold a value of
+500. If you printed byte_int out, it would display as -12.

  Doug Gordon
  GHCS Software



-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to