Revised RFC on range design for D2
Benji Smith
dlanguage at benjismith.net
Fri Sep 12 12:37:23 PDT 2008
Andrei Alexandrescu wrote:
> Consider iterating over an array of int[], specifically an int[][]. Then
> when you call r.head you see the current int[]. You can store it and use
> it a few steps later or even after the iteration is done for as long as
> the array is around.
>
> Contrast that with iterating a file containing lines of integers. The
> file has a buffer of type int[]. Every time you call r.next, the file
> range reads a new line, parses the integers, and REFILLS the array with
> them. If if generated a new array every line, that would cause a great
> deal of allocations.
Gotcha. I understand now.
Thinking off the top of my head, though, is it actually necessary define
input ranges as reusing the same array? Wouldn't a peephole optimizer
get rid of those extra allocations anyhow?
--benji
More information about the Digitalmars-d-announce
mailing list