Another prayer for invariant strngs

0ffh spam at frankhirsch.net
Fri Jul 13 01:01:29 PDT 2007


Robert Fraser wrote:
> 2. Performance. While writing my own code, I can pretend "string" is
> invariant (or use my own invariant(char[]) alias), but when passing to,
> or receiving code from library functions, this is not possible. This
> means that in each of these situations I must take two,
> performance-draining precautionary measures: i. Duplicate the string
> every time it's passed in or out of my code. ii.Synchronize
> multithreaded access to strings/acquire locks/etc.

I don't quite see this point. The way I understand D2.0 strings (which
may be like so much wrong, but still), with invariant(char)[] you can
be sure the characters will never change, so there is totally no reason
to duplicate that string. Only the pointer to the characters and the
length information are mutable.

> Invariant strings have precedent: they're used in Java, .NET, Perl,
> Python, Ruby and quite a few other languages.

In my book, precedence in itself is no argument - except for lemmings. ;-)

Regards, Frank



More information about the Digitalmars-d mailing list