1) Each process has 4 GB of virtual memory space, but it does not need to be allocated immediately. The operating system tells the MMU which parts of the physical memory are mapped to virtual space and which parts are not displayed at all. Access to components that are not displayed will cause a processor error, and the operating system usually generates segfault. There is also a no token that tells the processor that the memory area is not in physical memory but is in the swap area, so the processor is faulty and the operating system changes the page back to physical memory, then resumes the process when it stops. To describe a table of process pages, you only need a few bytes of memory, so 100 processes will not use this large memory until they request it.
2) There are many memory allocation algorithms. Typically, the operating system allocates only large blocks of memory at a time, and therefore calls to malloc () sometimes cause the operating system to be called, but most of the time these are implementation details of the standard C library that handle micromanagement. There is no guarantee that access outside the array will cause seg to fail, as it may be part of another array that was previously malloc'ed, or part of the free space that the standard library monitors for the future and therefore will not be segfault. However, there are debugging tools like valgrind that will detect such errors.
3) Information about where each segment is located depends on the operating system, but there is no need to know for general and portable code.
For more information on all of these topics, refer to the osdev wiki, in particular, the parts on paging and memory allocation .
source share