toString, to!(char[]) & co

Fawzi Mohamed fawzi at gmx.ch
Wed Mar 10 15:16:43 PST 2010


On 10-mar-10, at 23:23, Andrei Alexandrescu wrote:

> On 03/10/2010 04:16 PM, Fawzi Mohamed wrote:
>> If you look at the allocations needed for a toString, one sees the
>> allocation of a lot of small strings, alloacation for the  
>> concatenation
>> of a couple of the small strings, then again for the larger blocks  
>> until
>> you get the final string.
>> To me it reeks of bad design, especially if there is an easy way to
>> avoid most problems, a way that can avoid almost all allocations.
>>
>> I find it much better to base everything on something like
>> void writeOut(T,S...)(void delegate char[]sink, T object,S  
>> formatting)
>> that outputs to a sink, so that you can have output without memory
>> allocation.
>> (well my version is little more complex because I want to accept also
>> other stuff not just a sink
>> http://github.com/fawzi/blip/blob/master/blip/io/BasicIO.d
>> )
>
> I agree. For the longest time I wanted to find the time to output  
> and format stuff to arbitrary output streams (including string  
> appenders as a particular case), but couldn't find the time.

good, well time is always too short :)

Fawzi



More information about the Digitalmars-d mailing list