What is a register int?
What is the difference between a register int and a normal int?
Why not use register int where we can instead of using a normal int?
What is a register int?
What is the difference between a register int and a normal int?
Why not use register int where we can instead of using a normal int?
register int storage area is CPU registersWhat is a register int?
The only diffrence is storage area. Normal ints are stored in RAMWhat is the difference between a register int and a normal int?
Typical CPU will have 5-30 (Completely depends on architecture) general pupose registers, so they are very few. One have use them wisely. Most of the compilers will handle this for you, they will try to fit normal int to registers, and if registers are not available normal int is used even for register int. (Note you may need to set the optimization level in compiler)Why not use register int where we can instead of using a normal int?
Variables which are used very often (many statments) are typically declared as register int
Examples:
1. Loop control varables
2. Array offset index
3. Pointers (specially array pointers, memory pointers)
Main reason behind this is that CPU can operate on data in registers only, so it has load the variables in to registers and then operate on them. If we already have frequenty used data in registers, loading time is saved (which is significant on CPUs using external memory)
When you know how to do it then you may do it wrong.
When you don't know how to do it then it is not that you may do it wrong but you may not do it right.
Thanks for that very informative answer!
Bookmarks