www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Reducing dependence on GC in Phobos

Recently, std.string.splitterLines() was added to Phobos:

   https://github.com/D-Programming-Language/phobos/pull/2987

The previous way to split lines was std.string.splitLines(). splitLines()
always 
allocated memory. splitterLines() never does.

splitterLines() hews to the emerging trend in Phobos components to eschew 
allocation by using lazy ranges instead of eager allocation (std.algorithm does 
this pervasively).

It's a bit harder to write code this way than the traditional way, but it's a 
big win to be able to provide components that are independent of how the user 
chooses to do memory allocation. Fortunately, there are plenty of models in 
Phobos for how to do this one can use as guides.

(One of the dazz things about this style of programming is often the need for 
allocation at all simply evaporates.)

I'd like to move forward with these techniques for the rest of allocating 
components in Phobos for which it makes sense. There's plenty more just in 
std.string!

(Note: the existing allocating components won't be removed. The non-allocating 
ones will be additions, as they have a different interface.)
Feb 16 2015