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?
Printable View
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?
VB.NET
VB Code:
Dim myInteger As INT64
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.
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)Quote:
Do you know if there is a execution advantage by using to 64 bit?
Also are the API return values defined as 64?
I haven't seen any API's that return a 64bit value...yet.
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....Quote:
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
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
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.
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.Quote:
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....
Personnalt I use declare as Double and have never ran into any probelms (crossing my fingers) :D
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. ;)Quote: