Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The answer to your question largely depends on which compiler you use and the internal workings of your CPU, memory controller and memory architecture (cache and external memory).<br> You only have control over the compiler (assuming you are using C or C++ compiler). Compilers have different modes for cases when you are using variables which are smaller than a word size. There are flags for speed optimization and memory optimization. Depending on which of those flags are turned on, the compiler may choose to generate code which packs all four variables (in your case) into one word. Or the compiler may choose to allocate a memory word for each of the variables but use a particular byte to store the actual value. The way the compiler will do it for each of the cases is to generate different set of instructions for the CPU. In the latter case, if the variable is read from memory then the entire word is put on the bus and then into a general purpose register. In the former case, the word is put in the register but then the word can get shifted bit wise and the other bits can be zeroed out by using logic AND operation. That way the right byte is going to be in the register. Or may be the CPU architecture supports byte level access in a word in which case it will be only one operation performed by the CPU. In the end, it is a good idea to understand what happens inside but you will not care much because the set of instructions generated by the compiler will work correctly from your standpoint. The only time you will care is when you write performance sensitive software. In that case you will need to know the details of your CPU and memory as well as the flags supported by the compiler.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload