Process address space on virtual address systems
In the below link, answer given by Sdaz MacSkibbons gives a brief overview of process address space on virtual address systems.
What happens when a computer program runs?
Now suppose every process gets 4GB virtual address space. Now does that mean that the top addresses of this virtual address space will get stack part (Suppose stack address starts from 0) and address space from bottom will be allocated to text, data, globals and heap. Since size of heap changes, do new malloc allocations will map virtual address space pages to real memory directly or do they check whether previously allocated virtual address pages to heap are free/available. And How about if we need large amount of heap memory, like greater than 4GB, than how do process supports that ?
Thanks in advance.
The answer you link to simply shows a way things could be done.
Assuming you have a logical 4GB address space, not all of those might be valid or even potentially valid virtual addresses.
Some part of that logical address space will be devoted to the system. It is unlikely the system will use or come close to using the entire logical address range devoted to it.
There will be other areas in the logical address space that will not have valid logical addresses.
Next, describing memory as heap and stack is misleading. Heap and stack are simply read/write memory. There is nothing special about them and the operating system does not care what the memory is being used for.
Think of program sections as being: - Executable, readonly - No execute, read/write - No execute, readonly
Your second question is about malloc. Malloc implementations manage pools of read/write memory. Malloc tries to process a memory request by returning memory from the pool. If there is not sufficient memory available, malloc will increase the size of the pool by mapping more virtual memory to the logical address space.
If applications need to allocate large amounts of memory, they usually do not use malloc. They operating system services instead. If you have a 4GB address space, you cannot allocate blocks larger then 4GB.
链接地址: http://www.djcxy.com/p/80192.html上一篇: 如何找出GHC的数据类型的内存表示?
下一篇: 在虚拟地址系统上处理地址空间