std::string responsible for half the allocations in chrome

Sean Kelly via Digitalmars-d digitalmars-d at puremagic.com
Sun Dec 7 10:08:51 PST 2014


On Saturday, 6 December 2014 at 16:32:30 UTC, H. S. Teoh via 
Digitalmars-d wrote:
> On Sat, Dec 06, 2014 at 05:10:09PM +0100, Joseph Rushton 
> Wakeling via Digitalmars-d wrote:
>> On 05/12/14 23:03, deadalnix via Digitalmars-d wrote:
>> >http://www.reddit.com/r/programming/comments/2ocmvb/stdstring_is_responsible_for_almost_half_of_all/
>> >
>> >Looks like someone need immutable(char)[] .
>> 
>> Someone asked me the other day, and I realized I didn't have a 
>> ready
>> answer as I'd never particularly considered it: why is it
>> important/beneficial that the string type be immutable(char)[] 
>> ?
>
> Immutable, because then you can freely use slices as substrings 
> without
> worrying that the substring you hand to function X might get 
> modified by
> unrelated function Y while function X is not quite done with 
> processing
> it yet.

At the same time, immutable means that if you do need to do any 
string manipulation, you need to copy the string first.  I think 
whether immutable means more or less allocations than 
mutable/const is actually more dependent on application design 
than anything, and some applications can't afford the copying 
that using immutable requires.


More information about the Digitalmars-d mailing list