|
-
Sep 28th, 2002, 11:29 AM
#1
Thread Starter
PowerPoster
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?
-
Sep 28th, 2002, 11:30 AM
#2
I wonder how many charact
Last edited by nemaroller; Sep 28th, 2002 at 11:39 AM.
-
Sep 28th, 2002, 12:33 PM
#3
Thread Starter
PowerPoster
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.
-
Sep 28th, 2002, 12:52 PM
#4
I wonder how many charact
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.
-
Sep 28th, 2002, 01:12 PM
#5
Thread Starter
PowerPoster
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.
-
Sep 28th, 2002, 01:26 PM
#6
I wonder how many charact
IF you wrote just:
VB Code:
For i= 1 to 100000 '100,000
'do somethin
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:
Dim i As Integer
For i= 1 to 100000 '100,000
'do somethin
Next
You would hit an overflow error at 32,000 something....
-
Sep 28th, 2002, 07:51 PM
#7
Fanatic Member
Originally posted by nemaroller
IF you wrote just:
VB Code:
For i= 1 to 100000 '100,000
'do somethin
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:
Dim i As Integer
For i= 1 to 100000 '100,000
'do somethin
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.
-
Sep 28th, 2002, 07:53 PM
#8
PowerPoster
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....
-
Sep 28th, 2002, 08:24 PM
#9
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|