2008SpCS61C-L06-ddg-cmem-6up

2008SpCS61C-L06-ddg-cmem-6up -...

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

View Full Document Right Arrow Icon
CS61C L06 C Memory Management (1) Garcia, Spring 2008 © UCB Lecturer SOE Dan Garcia www.cs.berkeley.edu/~ddgarcia inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 6 – C Memory Management 2007-02-04 Hello to Justin H from Seattle, WA Intel: High Speed Memory Intel says it has found a way to make its NAND flash memory five times faster (200MB/s) than before. They call it “high-speed NAND”, and it is expected to be available this summer. Great for hybrid (disk + flash) drives ! www.computerworld.com/action/article.do?command=viewArticleBasic&articleId=9060581 CS61C L06 C Memory Management (2) Garcia, Spring 2008 © UCB Review Use handles to change pointers Create abstractions (and your own data structures) with structures Dynamically allocated heap memory must be manually deallocated in C. Use malloc() and free() to allocate and de-allocate persistent storage. CS61C L06 C Memory Management (3) Garcia, Spring 2008 © UCB Don ʼ t forget the globals! Remember: Structure declaration does not allocate memory Variable declaration does allocate memory So far we have talked about several different ways to allocate memory for data: 1. Declaration of a local variable int i; struct Node list; char *string; int ar[n]; 2. “Dynamic” allocation at runtime by calling allocation function (alloc). ptr = (struct Node *) malloc(sizeof(struct Node)*n); One more possibility exists… 3. Data declared outside of any procedure (i.e., before main ). Similar to #1 above, but has “global” scope. int myGlobal; main() { } CS61C L06 C Memory Management (4) Garcia, Spring 2008 © UCB C Memory Management C has 3 pools of memory Static storage : global variable storage, basically permanent, entire program run The Stack : local variable storage, parameters, return address (location of “activation records” in Java or “stack frame” in C) The Heap (dynamic malloc storage): data lives until deallocated by programmer C requires knowing where objects are in memory, otherwise things don ʼ t work as expected Java hides location of objects CS61C L06 C Memory Management (5) Garcia, Spring 2008 © UCB Normal C Memory Management A program ʼ s address space contains 4 regions: stack : local variables, grows downward heap : space requested for pointers via malloc() ; resizes dynamically,
Background image of page 1

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

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

Page1 / 4

2008SpCS61C-L06-ddg-cmem-6up -...

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

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