Code location in memory

Probably a trivial question, but somehow I cant find an answer.

So there's a heap and a stack where objects / variables are stored, but where is the running progam's code stored ? I'm guessing it's in some read only memory area as otherwise we could modify it while it's running.

I'm not looking for some really in depth explanation.
I'll be grateful for insight or links on that matter.
Last edited on
The above links describe how variables are handled on the stack and the heap, but didn't address the executable code portion of your question.

When the operating system's loader instantiates an object file in memory, it essentially allocates two distinct areas from the operating system's available memory.
1) instructions and read-only variables are allocated in a memory segment that will be marked as read-only by the operating system. If more than one instance of the same object file is run, the muliple instantes of the program will share this segment.
2) One or more memory segments are allocated that will contain globals, the stack, and the heap. Whether a single segment or multiple segments are allocated, depends on the OS and/or hardware platform.
Topic archived. No new replies allowed.