Announcement

Collapse
No announcement yet.

Integer vs Byte data type

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Integer vs Byte data type

    The PB/DOS 3.50 user's guide describes integers as the "simplest and fastest numbers" in PB, whereas byte variables "are particularly useful for storing small unsigned integer quantities".

    I know that 16-bit x86 processors are optimized for integer calculations (ie they can operate on a 16 bit value in a single operation) so calculations using byte variables certainly can't be faster than calculations involving integer variables.

    Now I'd like to ask the 'expert' PB community (assuming operands and calculation results fall between 0 and 255):
    • *In general, should I prefer integer variables to byte variables when these variables are only used for calculations or loops (but are not saved to a file)?

      *Are calculations or loops any slower when I use byte variables instead of integer variables or is there really no difference?
    Thank you for your replies!

    Heinz Salomon

    [This message has been edited by Heinz Salomon (edited January 20, 2005).]

  • #2
    Integers are emphasized in PB/DOS. For PB/CC and PB/Win, you
    will find that Longs have superceded Integers.

    Modern processors use a "look-ahead" approach to reading the
    contents of memory, so as long as the predictive behavour of
    your program follows it's logic, there is no discernable
    difference in terms of memory access speed. Much older PCs
    that read byte at a time or word at a time were not benefitted
    by the presence of a local high-speed memory cache with a
    look-ahead feature.

    The move to Longs rather than Integers or Bytes fits in with
    the new numeric types that the more modern compilers support.
    When a compiler is "optimized" to handle a certain numeric
    type, that means that efforts are first made to convert other
    numeric types to its form for processing if that accomodates
    the whole expression. If the other numeric variables used
    are already of that type, it saves times and instructions not
    having to expand those numbers to fill the larger type.

    Longs, of course, accomodate everything short of Quads,
    currency, extended, and floating point formats. You might
    say that they went for the mid-point in the numeric range.
    Longs generally accomodate the majority of mathematical
    operations that do not require fractions. Decimal Places
    can also be handled by longs if the decimal place adjustment
    is held off until the final stages of computation or display.

    However, this is not the most pressing concern. Bytes are
    very handy because they have the same bit count as character
    codes in the ASCII table, which are the standard symbolic
    code used for the keyboard, monitor, and printer. Bytes can
    also allow you to minimize storage requirements when small
    values between 0 and 255 need to represented. With today's
    powerful and fast PCs. only extensive computational or
    reiterative processes are likely to benefit by being overly
    selective as to the numeric type selected.

    ------------------
    Old Navy Chief, Systems Engineer, Systems Analyst, now semi-retired

    [This message has been edited by Donald Darden (edited January 20, 2005).]

    Comment


    • #3
      Heinz,
      don't use BYTEs unless you really need to.
      16bit integers are much faster in PB/DOS for everything.

      Paul.

      ------------------

      Comment


      • #4
        Got the message... thank you for your replies!

        Heinz Salomon

        ------------------

        Comment

        Working...
        X