Is there any chance that malloc () will return the same starting address in two processes.
Yes, but thatβs not a problem.
What you do not understand is that operating systems first process your physical space for you - programs, etc. see only virtual addresses. There is only one virtual address space, however, the operating system (now let it be 32-bit) shares this. On Windows, the upper half (0xA0000000 +) refers to kernel processes and the lower half to user processes. This is called a 2 GB / 2 GB split. On Linux, the partition is 3 GB / 1 GB - see this article :
Kernel memory is first defined with PAGE_OFFSET, which on x86 is 0XC0000000 or 3 gigabytes. (The 3gig / 1gig separation is defined here.) Each virtual address above PAGE_OFFSET is the kernel, any address below PAGE_OFFSET is the user's address.
Now, when the process is switched (unlike the context switch), all pages belonging to the current process are not displayed from virtual memory (not necessarily swapping them), and all pages belonging to the future -run process are copied to (disclaimer : this may not be entirely true, you can mark pages dirty, etc. and copy to access, theoretically).
The reason for the gap is that, for performance reasons, the upper half of the virtual memory space may appear in the kernel of the operating system.
So, although malloc can return the same value in two given processes, it does not matter, because:
- physically, they do not match the address.
- processes do not exchange virtual memory anywhere.
For 64-bit systems, since we currently use only 48 of these bits, there is a gap between the bottom of the user mode and the kernel mode, which is not addressed (for now).
user257111
source share