- While compiling code/task the compiler/linker has to decide/assign address of code/text(instructions), data (global variables), stack.
The system with MMU (Memory Management Unit)(i.e., supports virtual memory),
The compiler/linker is free to take any address as it needed.
While the code is executing MMU will translates Virtual address to physical address.
The system without MMU: the compiler and linker has to assign address dependent on the system memory. Because it should not use the memory region of other task.
Advantage: the compiler/linker need NOT to bother about the memory map of the system.
- Programming of task will be easier, because the memory space actually allocated to the task is very high when compared to the system memory availability, (This acheived by keeping the needed datas/code in the main memory and keeping the rest in secondary storage).
- System service function need not to be duplicated. All system service's virtual address of all the tasks could be mapped to same physical address which contains the system service.
- In simple terms, the memory allocation need not to be considered while coding a task which would be handled while executing the task by MMU.
Coming to your Question:
If virtual memory is stored in main memory, then why even use it in the first place?Why not just use main memory?
Vitural memeory/address is representation of physical address/memory .
This representation helps in acheiving easier multitasking implementation, memory management, developing task without system memory details..