Under the hood, the compiler creates an instruction that moves the immediate value 37 into a register. 37 is defined directly in the instruction strea

Where does constant data go?

submited by
Style Pass
2024-04-18 04:30:15

Under the hood, the compiler creates an instruction that moves the immediate value 37 into a register. 37 is defined directly in the instruction stream.

Interestingly, under the hood, something else happens. There are no immediate float values. So the compiler adds a float memory to the data segment of the executable and copies the value from there into a register.

Similar to the float value, but this time it only loads the address to the data segment. The title variable is a pointer, that points to the data segment.

It also stores the list of chars in the data segment of the executable memory, after all, the right side of the statement is the same, but then calls the constructor of string with it, allocates memory on the heap and copies to it.

You wanted constant data, you got a duplicate and a heap allocation! The const is really only cosmetic, so your colleges don’t touch your things.

Leave a Comment