Results 1 to 9 of 9

Thread: Integer, Long and 64 bit numbers

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jul 2001
    Location
    Tucson, AZ
    Posts
    2,166

    Integer, Long and 64 bit numbers

    I believe I recall a discussion that when we moved from 16 bit (Windows 3.0) to 32 bit (Win95/98) that it was best to use longs instead of integers.

    Why I don't recall?

    If we move to 64 bit what should we use?

  2. #2
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    VB.NET
    VB Code:
    1. Dim myInteger As INT64
    Last edited by nemaroller; Sep 28th, 2002 at 11:39 AM.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jul 2001
    Location
    Tucson, AZ
    Posts
    2,166
    Thanks nemaroller.


    Do you know if there is a execution advantage by using to 64 bit?
    Also are the API return values defined as 64?

    As I recall now, it was contended that by using a long in lieu of an integer in 32 bit the compiler didn't have to covert from its native format. In tests I ran I didn't see any performance hit by using an integer -- however API usage did require a long since this was its normal return value under 32 bit.

  4. #4
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Do you know if there is a execution advantage by using to 64 bit?
    Also are the API return values defined as 64?
    No advantage to using 64bit right now, unless you have a 64bit processor (I don't know if Intel or AMD has released one yet for personal pc's), and a newer compiler that would take advantage of that... (VB.NET)

    I haven't seen any API's that return a 64bit value...yet.
    As I recall now, it was contended that by using a long in lieu of an integer in 32 bit the compiler didn't have to covert from its native format. In tests I ran I didn't see any performance hit by using an integer
    The performance hit is not big, you'd have to use a large loop or write code that transfered shifted large amounts of data, to realize the difference....

    I imagine VB puts the loop counter in the register... as the article below seems to suggest:

    http://216.239.39.100/search?q=cache...hl=en&ie=UTF-8
    Last edited by nemaroller; Sep 28th, 2002 at 01:01 PM.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jul 2001
    Location
    Tucson, AZ
    Posts
    2,166
    Thanks nemaroller.

    Suprised article didn't test integer also. Would also expect that if there was an advantage to long over integer that the compiler would make this conversion for you -- just a thought.

  6. #6
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    IF you wrote just:
    VB Code:
    1. For i= 1 to 100000 '100,000
    2. 'do somethin
    3. Next

    I would assume the compiler would automatically use a LONG... because an Integer would not be large enough to hold 100,00. But the next largest datatype is Long, so it would use that.

    If you wrote:
    VB Code:
    1. Dim i As Integer
    2. For i= 1 to 100000 '100,000
    3. 'do somethin
    4. Next

    You would hit an overflow error at 32,000 something....

  7. #7
    Fanatic Member WorkHorse's Avatar
    Join Date
    Jul 2002
    Location
    Where you live.
    Posts
    591
    Originally posted by nemaroller
    IF you wrote just:
    VB Code:
    1. For i= 1 to 100000 '100,000
    2. 'do somethin
    3. Next

    I would assume the compiler would automatically use a LONG... because an Integer would not be large enough to hold 100,00. But the next largest datatype is Long, so it would use that.

    If you wrote:
    VB Code:
    1. Dim i As Integer
    2. For i= 1 to 100000 '100,000
    3. 'do somethin
    4. Next

    You would hit an overflow error at 32,000 something....
    I think a variant is interpreted as a decimal data type (which is the largest numeric data type in VB6). The second loop will overflow on the For statement because it tries to load 100000 as an integer in the For statement, not as the loop runs. A Do loop using i = i + 1 would overflow at 32767 if i is an integer.

  8. #8
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Personnalt I use declare as Double and have never ran into any probelms (crossing my fingers)
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  9. #9
    Fanatic Member WorkHorse's Avatar
    Join Date
    Jul 2002
    Location
    Where you live.
    Posts
    591
    The acrticle is misleading. You won't get a 7000% performance increase using a Long instead of Single. That difference is over a large number of iterations. A For loop isn't a good test because the loop is handled internally by VB--not necessarily using your variable. A Do loop with I = I + 1 would be a better test. I get a much smaller percent difference on my PC--under 1/10 second per 10 million iterations (your values may vary). Unless you really need to do tons of cacluations and really need to save a tiny fraction of a second and really need to do it in VB, use whatever works best. Double is nice because you (probably) won't overflow and can Step by fractions in a For...Next without wondernig why the code doesn't work right.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width