about std.string.representation

Jared Miller none at example.com
Wed Nov 13 21:20:39 PST 2013


To expand on bearophile's answer, a dynamic array is basically a 
package of two things: a length and a pointer to the contents. 
Each of these is 8 bytes on a 64-bit system, thus the sizeof a 
dynamic array is 16 bytes.

You are asking how char, wchar, and dchar correspond to integer 
types. That is defined here: http://dlang.org/type.html.

char  = 1 byte  (ubyte)
wchar = 2 bytes (ushort)
dchar = 4 bytes (uint)

To show this, print the sizeof an element in each of those arrays:

   writeln( typeid( t ),  ' ',  t[0].sizeof,  ' ', 
t.representation() ); // 1
   writeln( typeid( c ),  ' ',  c[0].sizeof,  ' ', 
c.representation() ); // 1
   writeln( typeid( dc ), ' ', dc[0].sizeof, ' ', 
dc.representation() ); // 4
   writeln( typeid( wc ), ' ', wc[0].sizeof, ' ', 
wc.representation() ); // 2


More information about the Digitalmars-d-learn mailing list