CMPT 295

Happy Lunar New Year!

Homework

Memory Allocation Example

Where does everything go?

Code:

#include ... //shared libraries
char hugeArray[1 << 31]; /* 231 = 2GB */// data
int global = 0; // data
int useless(){ return 0; } // text
int main ()
{
  void *ptr1, *ptr2; //stack
  int local = 0; //stack
  ptr1 = malloc(1 << 28); /* 228 = 256 MB*/ //heap
  ptr2 = malloc(1 << 8); /* 28 = 256 B*///heap

  /* Some print statements ... */
}

Stack in list form:

Why 8?

1) %rsp contains the memory address 0x0018

Register Memory Address
%rsp 0x0018
  0x0010
  0x0008

2) %rsp contains the memory address ____

Register Memory Address
  0x0018
%rsp 0x0010
  0x0008

Last Lecture

(unless I’m missing something, this contains exactly the same slides as Lecture 14 here. Everything in the “example 1 steps X and Y” portion, read that for this section)

Summary

Next Lecture