Does foreach on array literal allocate?
    Sergey Gromov 
    snake.scaly at gmail.com
       
    Thu Dec  4 17:31:35 PST 2008
    
    
  
Fri, 5 Dec 2008 03:58:39 +0900, Bill Baxter wrote:
> Does anyone know off the top of their head if code like this allocates
> or not with current DMD 1.x compilers?
> 
> foreach(x; [1, 2, 3, 4])
> {
>      // do something non-allocating with x
> }
> 
> And is the answer different if the values are only known at runtime?  Like here:
> 
> void a func(int a1, int a2, int a3)
> {
>    foreach(x; [a1,a2,a3]) {
>          // do something non-allocating with x
>    }
> 
> }
AFAIK array iteration never used delegates.  Therefore it shouldn't have
been ever allocating, and it shouldn't now.
    
    
More information about the Digitalmars-d
mailing list