Memory leak with dynamic array

Steven Schveighoffer schveiguy at yahoo.com
Tue Apr 13 08:29:03 PDT 2010


On Tue, 13 Apr 2010 11:15:15 -0400, Joseph Wakeling  
<joseph.wakeling at webdrake.net> wrote:

> As for iteration, I don't know to what degree D's foreach() across
> arrays compares to for() commands in C++ -- I guess it should be pretty
> close in performance, no?

D special cases foreach on arrays to basically be a standard array for  
loop, i.e.:

foreach(x; arr)
{
    ...
}

translates to something like:

auto __len = arr.length;
for(uint __i = 0; __i < __len; ++__i)
{
    auto x = arr[__i];
    ...
}

Although it may be even further optimized, I'm not sure.

-Steve


More information about the Digitalmars-d-learn mailing list