> -----Original Message-----
> From: Discussion of advanced .NET topics. 
> [mailto:[EMAIL PROTECTED] On Behalf Of 
> Curt Hagenlocher
> Sent: Wednesday, August 08, 2007 4:37 PM
> To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM
> Subject: Re: [ADVANCED-DOTNET] compiler considerations
>
> > passed to Writeline or prepared in advance. Furthermore, it seems 
> > unwise that in the following code would perform boxing 
> 10,000 (0x2710) times.
> >
> > for(int i=0; i<10000; i++) WriteLine("{0}",1);
> 
> 
> Sure it seems unwise, but this example is both unrealistic 
> and pathological.  And the performance issue (such as it is) 
> can trivially be avoided with a small change in the user 
> code.  All in all, I'd prefer my optimization dollar to be 
> spent somewhere else.
> 

Unless you have explicit statistics and usage data I would not dismiss
this scenario as unrealistic.

How many times you've seen a variant of the following code:
<YourPreferredLoggingStream>.WriteLine("Number of foo-bars is: {0}",
constant_NumOfFooBars);

As a conjecture only, based on my subjective experience, generally if
there is a constant in your program, probably it would be printed. And
that for
"printed" alone - probably it would be boxed much more than once.

Also, why bother with interning strings but not bother interning
constants? Arguably there is no conceptual underlying difference between
the two interning implementations (thus you could probably keep the
$0.99 after the implementation cost). The only difference is in what we
predict would be the usage. It is assumed that if it is a string literal
then it would be extensively used. I am not at all sure that same
assumption is invalid for boxing of non-string constants.

Igal.

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to