Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to pass a date to a DLL?
Message
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00065737
Message ID:
00066084
Views:
55
>>
>>Ok, I got it! But why not simply:
>>
>>bitand(lnRight, 0x7f)*256 + lnLeft
>>
>>Vlad
>
>Traditionally, a low level bitshift is Much faster than multiplication by a floating point value. But since this is foxpro, and we are actualling calling functions, the performance gains are probably lost.

I just tested this. Using shifting vs. multiplication is faster with about 3/10000000 seconds.

>The readability is also reduced using my technique whereas in C++ it would be:
>
>unsigned char lcShort[2];
>short x;
>// ...
>x = ((lcShort[1] & 0x7f) << 8) | lcShort[0]);
>x = (lcShort[1] & 0x80) ? (-x) : (x);
>
which would be thousands of times faster than the equivalent FoxPro and tens of times faster than the equivalent C++ using multiplies instead of bit operations.

A good C/C++ compiler should optimize internally code that multiplies by 256 using a right shift, IMHO.

>Of course in C++, the initial reason we had to unpack a short becomes moot :-)

Right. :)

Vlad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform