Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Why define constants
Message
From
26/10/2006 11:26:20
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
 
To
25/10/2006 16:14:33
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01164235
Message ID:
01164728
Views:
13
>>Then I #defined it as a constant and replaced all six occurrences of the string with this constant. I compiled it, and found the string in the fxp six times, in pretty much the same places as in the first fxp.
>>
>>So there's no pool - the constants still remain scattered throughout the code.
>
>That's a nice step forward in this discussion.
>
>What do you think that means, performance-wise, at execution. Would it suggest to you that #DEFINEd constants are faster?

Only slightly - since there's no pool, the address of a constant is short, it's within the line in which it's used, so there's no jump to a faraway segment of memory. With today's machines, that doesn't mean much.

Also, with VFP's dynamic loading of code, having a global pool of constants would only mean they are static, i.e. the whole block of constants being loaded once and kept in memory for the life of the app. Now with them being local to the statement, they are loaded when needed, and discarded when the routine goes out of scope. So they take up spaces only in the lines of code where they are used - with no difference between the case when they are literally in the line, or when they are #defined.

So, IMO, #define is a convenience, to be used when it improves the readability of the code, or when a language-specific application can't use translation lookup table etc. Speedwise or memory consumption-wise, the difference is negligible.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform