HW - Lecture 8

12191789 유호현


1-1.

Draw the memory map (process image) of the following program (ex1.cpp). What are the starting addresses of the code, data, heap, stack segment of this program and how many pages each segment occupies? What is the address of main function, the addresses of the global variables and local variables?

#include <stdio.h>
int x;
int y[10000];
int main(){
   int k;
   int *pk;
   pk=new int;
   printf(“ex1. &main:%p &x:%p &y:%p &y[9999]:%p &k:%p &pk:%p pk:%p\\n”,
          main,&x,&y,&y[9999],&k,&pk,pk);
   for(;;);  // to see memory map of this process
   return 0;
}

Untitled

Untitled

Untitled

Untitled


1-2.

Write another simple program, ex2.cpp (see below), and run ex2, ex1 at the same time. Confirm they have the same address for main function. How can they run at the same location at the same time?

#include <stdio.h>
int x1;
int main(){
   int *pk1;
   pk1 = new int;
   printf(“ex2. &main:%p &x1:%p\\n”, main,&x1);
   for(;;);  // to see memory map of this process
   return 0;
}

Untitled

Untitled