Timeline for Isn't the use of pointer variables a memory overhead?
Current License: CC BY-SA 3.0
6 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Sep 14, 2021 at 9:12 | comment | added | Caleth | The abstract machine that C++ is standardised against stores every variable at some location, but an implementation may do things "as-if" when it can prove there is no observable difference. If you never take the address of a variable, how can you tell that it has one? | |
Dec 14, 2015 at 23:27 | comment | added | Lawrence | @BasileStarynkevitch I'm not sure of the point you are trying to make with the observation that variables may be stored purely in registers. Could you please elaborate? | |
Dec 14, 2015 at 14:44 | comment | added | Basile Starynkevitch |
The compiler may be allowed to store some local variables in registers only, and most optimizing compilers are doing that (try with gcc -fverbose-asm -S -O2 to compile some C code)
|
|
Dec 14, 2015 at 14:41 | comment | added | TMN | @BasileStarynkevitch: You can suggest that variables stay in registers, but the compiler is not required to do so. Unless you're programming in assembler, you really don't have that level of control over immediate storage. And even in assembler, any subroutine you invoke will likely spill the registers onto the stack so it can use them for its variables. So for any non-trivial program, it's almost guaranteed your variables will spend at least some time in memory. | |
Dec 14, 2015 at 13:32 | comment | added | Basile Starynkevitch | Some variables are not stored in memory, but only in registers | |
Dec 14, 2015 at 10:20 | history | answered | Lawrence | CC BY-SA 3.0 |