2

I've been studying C++ for a while now and I'm curious about two things:

1.) When exactly are the virtual addresses generated for the program? Are most or all done at compile time or runtime? or does it depend?

2.) Once virtual addresses are generated, either by the compiler or computer, what is the exact process of program execution? The way I would guess would be:

  • Program code loaded into RAM first.

  • Then one instruction at a time gets loaded into the cpu for execution.

  • If instruction involves a load intruction then cpu calls back to RAM, via page translation table, for data which is then sent back to the cpu to finish execution.

Or something along those lines. Can someone confirm or deny this? or fill in any gaps? Thanks for any help.

Edit: From some of the responses so far it seems this question is more platform specific so I would ask what the process is for say a windows 7 computer.

drescherjm
  • 10,365
  • 5
  • 44
  • 64
Jason
  • 2,198
  • 3
  • 23
  • 59
  • ***When exactly are the virtual addresses generated for the program?*** Usually at the time of the program loads. – drescherjm Dec 29 '15 at 18:08
  • 1
    ***Program code loaded into RAM first.*** Program code is mapped into the virtual address space and pages possibly are loaded when needed. Meaning the OS does not need to load the entire program (or even all of the dlls) into virtual memory at before execution of the program starts. – drescherjm Dec 29 '15 at 18:11
  • 1
    All this is extremely platform-specific, and nothing that C++ concerns itself with. – molbdnilo Dec 29 '15 at 18:14
  • BTW C++ does not specify what behavior the OS does for these things. – drescherjm Dec 29 '15 at 18:14
  • Yeah, this concerns the OS rather than the language: the operating system doesn't care whether the executable it's doing this for is written in C, C++, FORTRAN or whatever. It's a reasonable question, but pick a platform and research it for that; when and if you have further questions, ask them about the OS. – Useless Dec 29 '15 at 18:19
  • 2
    The actual story is very complicated, but your version is a decent starting point. In reality, program code is not loaded into RAM first; it is loaded on demand. And modern processors typically consume many instructions at one time. And load instructions go through multiple levels of caching and memory access policy. But your version works well as a mental model. – Raymond Chen Dec 29 '15 at 20:03
  • Okay thanks for that confirmation. It definitely helps to have some sort of mental model in my head. – Jason Dec 29 '15 at 20:53

0 Answers0