Understanding `sizeof` return values on `Char` / `String`

sizeof('z') == 4 because a Char is stored as a 32-bit value (see ?Char). This is required so any Unicode codepoint can fit in a Char.

sizeof("z") == 1 because encoding “z” in UTF-8 takes only one byte.

Base.summarysize('z') == 4 because a Char is a simple value type.

Base.summarysize("z") == 9 because… hum I’m not sure: I thing this counts 8 bytes for the pointer to the region of memory that holds the string, and 1 byte for the string itself. But it should also count some bytes for storing the length of the string?

2 Likes