How is string from "..." different from string from a file ?
Steven Schveighoffer
schveiguy at yahoo.com
Mon Dec 12 10:08:57 PST 2011
On Mon, 12 Dec 2011 12:59:11 -0500, Timon Gehr <timon.gehr at gmx.ch> wrote:
> On 12/12/2011 06:37 PM, bearophile wrote:
>> Timon Gehr:
>>
>>> string fragString = readText( "Shader.vert" ) ~ '\0';
>>
>> I think using toStringz is more self-documenting.
>>
>> Bye,
>> bearophile
>
> There is nothing more self-documenting than actually appending the zero.
> Claiming toStringz is better in that regard is like saying a+1 is less
> self-documenting than doAddo(a) ;)
> There might be other benefits of using toStringz though, (for example,
> it won't add the zero if it is already there, but that does not apply
> here).
x ~ y *always* makes a copy of x, whereas toStringz(x) will (should?) use
append (which could potentially save another heap allocation). However,
I'm not sure what kind of state the result of readText is in.
-Steve
More information about the Digitalmars-d-learn
mailing list