Week4-Mem - xkcd.com 1 Static Allocation 0x804837c main!...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
1 xkcd.com
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Static Allocation Recall: static allocation happens at compile time based on variable definitions. int x = 2; int a[4]; int *b; int main() {} 0x804837c main 0x804957c init.data 0x8049684 uninit. data 0x8049588 2 0x8049688 ??? 0x804968c ??? 0x8049698 ??? 0x8049690 ??? 0x8049694 ??? SYMBOL TABLE: main 0x804837c .text f9 x 0x8049588 .data 04 b 0x8049688 .bss 04 a 0x804968c .bss 10
Background image of page 2
3 Dynamic Memory Allocation • In Java, Set s; // Memory is allocated for pointer s // Memory is allocated for object s = new HashSet(); • In C, int *a; /* Memory is allocated for pointer a */ /* Memory is allocated for a to point to */ a = (int *)malloc(10 * sizeof(int));
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Dynamic Allocation 0x804837c main 0x804957c init.data 0x8049684 uninit. data 0x8049588 2 0x8049688 0x9e15020 0x804968c ??? 0x8049698 ??? 0x8049690 ??? 0x8049694 ??? int x = 2; int a[4]; int *b; int main() { b = (int *)malloc( 4 * sizeof(int)); b[0] = 10; b[1] = 20; } 0x9e15020 10 0x9e15024 20 0x9e15028 0x9e1502c heap
Background image of page 4
5 SYNOPSIS
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 08/02/2011.

Page1 / 13

Week4-Mem - xkcd.com 1 Static Allocation 0x804837c main!...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online