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

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Aug 31 01:11:02 PDT 2014


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.

Ali



More information about the Digitalmars-d-learn mailing list