On Thursday, 8 May 2014 at 17:46:06 UTC, Andrei Alexandrescu wrote:
A discussion is building around https://github.com/D-Programming-Language/phobos/pull/2149, which is a nice initiative by Walter to allow Phobos users to avoid or control memory allocation.

First instance of the pull request copied the inputs into an output range.

The second instance (right now) creates an input range that lazily creates the result. The element type of that range is the encoding type of the first argument (i.e. char or wchar most of the time). This is different from string/wstring/etc element-wise iteration because it'll be done code unit-wise, not code point-wise.

I'm with H. S. Teoh that we should prefer the input range approach. My limited experience with output ranges suggests to me that they really need to be the end point, where the data is actually leaving the program (writing to disk, over a network). And as Teoh mentions, if you need it in specific memory you can copy an input range into it.

D is already fairly lazy, and .array() is great for doing eager evaluation into the GC. For strings having something similar which allows for the original encoding to remain would be good.

Reply via email to