Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
#DEFINE - Why?
Message
De
01/04/2008 12:31:06
 
 
À
01/04/2008 12:20:28
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Titre:
Versions des environnements
Visual FoxPro:
VFP 9 SP2
Divers
Thread ID:
01306848
Message ID:
01307402
Vues:
10
>>>>I wonder how much memory we are talking about though? 100k? We are only talking about values like "LOOK_AT_THIS_COOL_DEFINE" and stuff like that. Maybe it comes down to how memory is assigned and it does save a bunch, but I'm thinking it's not really that much.
>>>>
>>>Hard to say. Try this test:
>>>
>>>#define CRLF chr(13)+chr(10)
>>>
>>>local lcStr
>>>
>>>for i=1 to 100000
>>>  lcStr = CRLF
>>>next
>>>
>>>vs.
>>>
>>>local lcCRLF, lcStr
>>>
>>>lcCRLF = chr(13) + chr(10)
>>>for i=1 to 100000
>>>  lcStr = lcCRLF
>>>next
>>>
>>
>>Why would the second example use significantly more memory? You're only creating one variable (albeit 100000 times). More cycles, yes ; more memory? no. Of course a smart compiler would probably only execute the 'lcStr=lcCRLF' once anyway :-}
>>
>>Regards,
>>Viv
>
>Actually the second example uses fewer cycles than the first. Granted we're talking nano-seconds of performance (but then again, we're talking about one variable's worth of memory), but it took the constant 1.2 seconds longer than the variable to execute a loop of 10,000,000 iterations.
>
>Note that this is a specific exception because the constant becomes an expression and not a value. So it makes sense to me since the constant has to execute two function calls (CHR(13) and CHR(10)) plus the concatenation while the variable only has to execute a memory lookup.

You're right of course. I was thinking in terms of simple string assignment and forgot about the overhead of evaluating the CHR()'s each time.
Regards,
Viv
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform