DMD 0.173 release

Ivan Senji ivan.senji_REMOVE_ at _THIS__gmail.com
Sun Nov 5 13:12:50 PST 2006


Bruno Medeiros wrote:
> Ok, so this one is about a feature of some releases ago, but you're 
> releasing new features faster than what we can keep up and look at :P

Aint that the truth. :)

> 
> Regarding array literals, it concerns me that each new literal 
> "evaluation" will create a new instance. For example a literal inside a 
> function will allocate a new instance every time the function is called. 
> Likewise a literal inside a loop will allocate a new instance for every 
> cycle of the loop!
> This strikes me as both inefficient (as there is no simple way to use 
> the opposite behavior: static/global instances) and inconsistent: other 
> kinds of literals, like string literals, are not instanced per 
> "evaluation" but instead are single/global/static instances.
> Is there any particular reason for this behavior? Because if not I'm 
> inclined to think it would be better that array literals work as string 
> literals (global/static instances). If the new'ed-instance behavior is 
> needed it could be easily emulated with dup'ing:
>   ar = [1, 4, 9].dup;
> 

I'm afraid that things have to be that way. It would make sense for 
array literals to be allocated only once if they were made of only 
constant values, but in cases like:

for(int i=0; i<100; i++)
{
    f( [i, i*i] );
}

I would expect a new instance to be created at each step in the loop.




More information about the Digitalmars-d-announce mailing list