edited by
1,856 views
0 votes
0 votes

I have learned that with run-time address binding, the program can be allocated frames in the physical memory non-contiguously. Also, as described here and here, every segment of the program in the logical address space is contiguous, but not all segments are placed together side-by-side. The text, data, BSS and heap segments are placed together, but the stack segment is not. In other words, there are pages between the heap and the stack segments (between the program break and stack top) in the logical address space that are not mapped to any frames in the physical address space, thus implying that the logical address space is non-contiguous in the case of run-time address binding.

But what about the memory layout in the case of compile-time or load-time binding ? Now that the logical address space in not an abstract address space but the actual physical address space, how is a program laid out in the physical memory ? More specifically, how is the stack segment placed in the physical address space of a program ? Is it placed together with the rest of the segments or separately just as in the case of run-time binding ?

edited by

1 Answer

0 votes
0 votes

Stacks grows from top to bottom. Stack segment is used to store all local variables and is used for passing arguments to the functions along with the return address of the instruction which is to be executed after the function call is over. Local variables have a scope to the block which they are defined in, they are created when control enters into the block. All recursive function calls are added to stack.

In order to support dynamic memory allocation heap is used, it may happen that we require some more memory then calculated so heap comes in picture

Text, data and BSS  spaced is reserved during compile time itself.

Different OS uses space between stack and heap differently.

Space between heap and stack  is contiguous most of the time, and is reserved. but if program want more space then allocated here comes heap into picture OS gives virtual memory to program, when ever there is need of physical memory the some data which is not currently in use is swapped in secondary memory and demand of program is fulfilled, after completion of task that data is swapped in into physical memory.

Stack segment is placed in physical address space of program

Related questions

0 votes
0 votes
1 answer
2
0 votes
0 votes
0 answers
4
SSR17 asked Feb 8
206 views
we have 8 pages (each side 32B) to store in physical memory of 2^32 bits how many bits are required to identify each page , according to me 3 bits are required but that i...