So can I assume that reading a char from memory should be as fast as reading a word (4 bytes)?
If the answer is YES than why do we even use char
variables when coding instead of word
variables (Other than the obvious type checking necessity).
So can I assume that reading a char from memory should be as fast as reading a word (4 bytes)?
If the answer is YES than why do we even use char
variables when coding instead of word
variables (Other than the obvious type checking necessity).
Why do we use char
variables? To avoid wasting memory. If you need 4 variables, you can fit 4 char
s in a single word, but if you declared them as int
it would take 4 words. If they only need to hold low numbers, all that extra memory is unnecessary.
One reason I can immediately think of is that we just want a byte for an ASCII character.
const WORD* str = W"Hello World?";
// ^ Some theoretical WORD-charactered string
Hehe.
And so because each character is just one byte, the processor would just have to do one fetch when getting, say, 4 characters.