When I attended an interview, last year, I had one question which I couldn’t answer. Hence that question made me to think more on this and collect and read more information on that.
Normally, all interviews normally start with Storage classes in C. Also, most of the interviews for 2-3 years of experienced people in so called Embedded Domain will have question on Memory layout of a C program which tells which type of data stored at which location. This information is really required for the people who involved in driver/firmware development. But interviewers expect from us atleast theoretical information on this.
Ideally, Memory Layout consists following segments where data/text is managed:
1) Code Segment: Consists of series of instruction.
2) Data Segment: (code, constant data, alternative data)
i) Stack Segment: Area where the current function data is managed.
ii) Heap Segment: Area where dynamically allocated data stored.
iii) BSS Segment (Block started by symbol): For uninitialized data.
Data segment is actually contains the static data which is decided on the compile time. Rest of Area is used by Stack and Heap which is actually modified run time. Stack grows from higher address to lower Address. Heap grows just opposite to the stack.
In our convention, memory for a program will have higher memories on top and lower memories on bottom.
Normally, all interviews normally start with Storage classes in C. Also, most of the interviews for 2-3 years of experienced people in so called Embedded Domain will have question on Memory layout of a C program which tells which type of data stored at which location. This information is really required for the people who involved in driver/firmware development. But interviewers expect from us atleast theoretical information on this.
Ideally, Memory Layout consists following segments where data/text is managed:
1) Code Segment: Consists of series of instruction.
2) Data Segment: (code, constant data, alternative data)
i) Stack Segment: Area where the current function data is managed.
ii) Heap Segment: Area where dynamically allocated data stored.
iii) BSS Segment (Block started by symbol): For uninitialized data.
Data segment is actually contains the static data which is decided on the compile time. Rest of Area is used by Stack and Heap which is actually modified run time. Stack grows from higher address to lower Address. Heap grows just opposite to the stack.
In our convention, memory for a program will have higher memories on top and lower memories on bottom.
There are some other ways of conveying the same concept. Following figure conveys the same concept but using different terminologies.
From the above figure, following points has to be remembered.
1. Colored sections are static data and other part is dynamic data. Static data means, values are decided at or before the compile time. Dynamic data means, at run time only, values are decided.
2. Alternative data means static and global data which included both initialized and uninitialized
3. Stack is for local data, heap is for dynamically allocated data, Constant data for ‘const’ data
4. Only Code data, constant data and initialized alternate data are stored as part of program file
Another info is, if you run the command size with any binary executable file, you will some needful info like follows.
I feel this information will definitely help us. I have given link below for reference. Once look into that which also make us clear.
Drop me a mail for anything - pramoda.ma@gmail.com
Reference:
http://book.chinaunix.net/special/ebook/addisonWesley/APUE2/0201433079/ch07lev1sec6.html
No comments:
Post a Comment