I can ask questions about dmd on windows here in this forum?

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Aug 31 01:36:58 PDT 2014


On Sun, 31 Aug 2014 01:11:02 -0700
Ali Çehreli via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com>
wrote:

> On 08/31/2014 12:37 AM, bearophile wrote:
> > Ali Çehreli:
> >
> >> Unless there is a specific reason not to, use 'string'. When you
> >> really need random access to characters, then use 'dstring'.
> >
> > So are the use cases for wstring limited?
> >
> > Bye,
> > bearophile
>
> Yes, without real experience, I am under that impression. Let's see:
>
> - char is UTF-8. UTF-8 is a variable-length encoding, from 1 up to 6
> bytes per character.
>
> - wchar is UTF-16. UTF-16 is a variable-length encoding, 2 or 4 bytes
> per character.
>
> - dchar is UTF-32. UTF-32 is a fixed-length encoding, exactly 4 bytes
> per characters.
>
> As I understand it, wchar would make sense when UTF-8 would take
> considerably more space than UTF-16 for a given text. Another case is
> when a wchar array is guaranteed to consist solely of 2-byte
> characters; it can then safely be used as a random access range.
>
> In contrast, a dchar array provides random access for any text but
> takes up more space for certain text than UTF-8 and UTF-16 (e.g. text
> consisting mostly of 1-byte characters in UTF-8 (e.g. ASCII)).
>
> So yes, wchar has limited use compared to the others.

The main use case for an array of wchar is to interact with Windows functions
which use UTF-16. There may be rare cases to use it otherwise, but the average
D program should just use string unless it needs random-access, in which case,
it should use dstring. wstring is ultimately of marginal use.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list