![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 | |
|
Programmer
Join Date: Sep 2005
Posts: 33
Rep Power: 0
![]() |
Quote:
as you pointed out compiler will decide whether to allocate the variable on a stack or register( this is for optimization?? right...i mean fetching from registers is much faster than from memory so is it? )..we can declare variables as having register storage type which suggests the compiler to store variable in a register since it will be used more frequently,but its mere suggestion compiler decides on it.. but i do not understand how compiler will decide on whether to store in stack or in register..i mean what are criterions...can you elaborate on that..I will be very grateful if you do. Thanks in advance |
|
|
|
|
|
|
#12 |
|
Newbie
Join Date: Sep 2005
Location: Cambridge, UK
Posts: 13
Rep Power: 0
![]() |
Here's a list ripped from: http://www.ece.utexas.edu/~valvano/assmbly/local.htm
Reasons why we place local variables on the stack include: - dynamic allocation/release allows for reuse of memory - limited scope of access provides for data protection - only the program that created the local variable can access it - since an interrupt will save registers and create its own stack frame, the code can be made reentrant. - since absolute addressing is not used, the code is relocatable - the number of variables is only limited by the size of the stack allocation that can be much larger than using local variables in registers Draw your own conclusions from that! |
|
|
|
|
|
#13 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 4
![]() |
The C standard from the getgo was to allocate auto variables in user stack space.
COBOL, FORTRAN and other languages didn't do that when C was originally designed. It's part of the reason that native C code is faster and less memory intense than FORTRAN and COBOL were. I learned C in 1978 on a Digitial PDP-8 with a 16K core. You had to mind your p's and q's memory-wise, so functions like alloca() really helped in memory management. alloca - like malloc but on the stack of the calling functions, freed when the function reutrns. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|