2 ms·
No, the character set is "Unicode". UTF-8, UTF-16, UCS-4, etc. are the character encoding. A character encoding is an algorithm for reading/writing characters
by jrockway 15y ago
No, the character set is "Unicode". UTF-8, UTF-16, UCS-4, etc. are the character encoding.
A character encoding is an algorithm for reading/writing characters from/to octet streams. A character set is ... a set of characters.
(Unicode has additional semantics; collation, etc.)
As to why you'd waste space with a 32-bit character representation: algorithmic efficiency. UTF-8 is efficient in storage, but it's not efficient for string operations: splitting a string is O(n), finding the nth character is O(n), determining the length of the string is O(n), etc. When each character takes the same amount of memory, though, these operations become constant time.
Finally, nulls don't cause problems because these are character arrays, not null-terminated octet arrays ("c strings"). Most big C apps don't use null-terminated octet arrays anymore; they use something like bstrings, or std::string, or their own homegrown implementation (SVPV in perl, etc.).