2,917 views
1 votes
1 votes
what is the meaning of the below paragraph

"The  large blank space between stack and the heap is a part of virtual address space but will require actual physical pages only if the heap or stack grows .Virtual address spaces that include holes are known as sparse address spaces.Using a sparse address space is beneficial because the holes can be filled as the stack or heap segments grow or if we wish to dynamically link libraries during program execution ".

 

My confusion is that this sparse address must be existing inside the main memory ,how come in becomes a part of virtual address space since there may be  a possibility that the stack and the heap segment are not allocated contiguously inside the main memory then how can they simultaneously grow towards each other .

1 Answer

0 votes
0 votes
On a virtual memory system, we are accessing main memory in units of "page". So, suppose a page size is 4KB, and a process needs 100 MB of main memory, we can allocate 25K page frames and these frames may be at any point in physical memory- they need not be contiguous, only each 4KB needs to be contiguous.

Now, the compiler generates addresses (virtual) which are continuous. During run time memory for heap and stack are also given and each of them is also continuous to facilitate variable addressing in programs. Now, the given paragraph talks about the space allocated to stack and heap. We can say stack starts from memory address 0x2FFF and heap from 0x1000 and stack goes down and heap grows up. During program run both the stack and heap size can change (during each function call, stack grows as new activation record gets created and during dynamic memory creation like malloc, heap grows). So, in the above example, I gave after sometime stack and heap spaces might collide. To avoid this we must leave enough gap between them and also limit the maximum memory space a process can take. In linux usually 8KB is the default stack limit for a process.

Related questions

257
views
0 answers
0 votes
2.5k
views
2 answers
1 votes
radha gogia asked Oct 19, 2015
2,467 views
If I say that the multi-level paging reduces the size of page table needed to implement the virtual address space of a process, then what is the meaning of last lines in the statement :"to implement the virtual address space of a process"