Operating System, C and process memory allocation -


we global variables , static variables initialized 0. question is, why have separate sections in binary initialized , uninitialized data.

i wrote following code -

int i; int j=0; static int k; static int l=0;  int main() {   static int m=0;   static int n;     printf("%d, %d\n",i,j);     printf("%d, %d\n",k,l);     printf("%d, %d\n",m,n);     return 0; } 

and output -

0, 0 0, 0 0, 0 

i checked output of objdump of bss section , section contained variables. per link -

http://www.cprogramming.com/tutorial/virtual_memory_and_heaps.html

typically, in each process, virtual memory available process called address space. each process's address space typically organized in 6 sections illustrated in next picture: environment section - used store environment variables , command line arguments; stack, used store memory function arguments, return values, , automatic variables; heap (free store) used dynamic allocation, 2 data sections (for initialized , uninitialized static , global variables) , text section actual code kept.

so, confused. if have 2 data sections why data placed in .bss section. , wanna understand .data contain.

can please me on this?

the .data section typically reserved variables values known @ compile time or larger blocks of constant memory such strings known @ compile time , static array blocks. .bss section stores unintialized or 0 valued variables because storing zero'es in .data section wouldn't make sense.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -