Manual Memory Management: Mastering malloc()

Slides:



Advertisements
Similar presentations
Dynamic Memory Allocation (also see pointers lectures) -L. Grewe.
Advertisements

Lecture 10: Heap Management CS 540 GMU Spring 2009.
Outline Midterm results Static variables Memory model
1 Dynamic Memory Allocation –The need –malloc/free –Memory Leaks –Dangling Pointers and Garbage Collection Today’s Material.
CSCI Rational Purify 1 Rational Purify Overview Michel Izygon - Jim Helm.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 10 – C: the heap and manual memory management.
CSE 333 – SECTION 1 C, Introduction to and Working with.
CSE 333 – SECTION 2 Memory Management. Questions, Comments, Concerns Do you have any? Exercises going ok? Lectures make sense? Homework 1 – START EARLY!
Week 3 Bell Works Political Science. Political Science Monday’s Bell Work Today’s bell work: Write down at least two pieces of information you learned.
YongChul Kwon CSE451 Section 1: Spring 2006 YongChul Kwon
Memory allocation & parameter passing
CMSC 341 Lecture 2 – Dynamic Memory and Pointers (Review)
Everyone starts with the same 24 hours per day…
UNITED STATES DAILY QUIZ
CSE 374 Programming Concepts & Tools
CSE 374 Programming Concepts & Tools
Recitation 6: C Review 30 Sept 2016.
COMPSCI 330 Design and Analysis of Algorithms
Weekly Warm Ups Week of September 12, 2016.
CSE 374 Programming Concepts & Tools
Days of the week NEXT.
Checking Memory Management
Lecture 16 CSE 331 Oct 5, 2016.
Lecture 17 CSE 331 Oct 3, 2014.
CSC 253 Lecture 8.
DAYS OF THE WEEK.
Storage.
CSE 333 – SECTION 2 Memory Management
Announcements Homework #7 due Monday at 3:00pm
Write into the day 19 September 2018
CSC 253 Lecture 8.
Terminos españoles de ingeneria de computacion.
Lecture 34 CSE 331 Nov 26, 2012.
UHS PHARMACY at Penn State
CSE 333 – SECTION 2 Memory Management
Sunday Monday Tuesday Wednesday Sunday Monday Tuesday Wednesday
Student October Collection
Schedules My Schedule Monday: 9:00-2:00 Work 3:00-6:00 Clean
Lecture 17 CSE 331 Oct 7, 2016.
CSE 333 – SECTION 2 Memory Management
Memory Allocation CS 217.
COMS S1007 Object-Oriented Programming and Design in Java
CSE451 Fall 2008 Section 1 Roxana Geambasu
Lecture 16 CSE 331 Oct 4, 2017.
Locations for CS 115 Activities
Lecture 18 CSE 331 Oct 12, 2011.
Course calendar (page 1 of 2)
CS 336/536: Computer Network Security Fall 2014 Nitesh Saxena
Homework Week of January 7th UNIT TEST TODAY! Monday Tuesday Wednesday
Visual For Weekly and Monthly Schedule
Extended Christmas Hours Thursday December 8th 9am -6:30pm Friday December 9th 9am -6:30pm Saturday December 10th 9am-6pm Thursday December.
Monday, FEBRUARY 5, Day 110 Welcome back! I hope you had a great weekend! Please enter quietly, distribute job cards and then fill in your agenda.
Wrt 105: practices of academic writing
Monday, January 9th – First Flight
Linked lists Prof. Noah Snavely CS1114
My School Days The first day back is Wednesday.
Contact
Prestwick Academy Study Skills for Parents
Monday, January 11 WINTER Bell Ringers Template.
Monday, January 15th MLK Day No School Fill in Agenda with:
Monday, January 11 WINTER Bell Ringers Template.
Attitude + Effort  Mastery
Monday, January 22nd Fill in Agenda with: Turn in Menu Projects
2011年 5月 2011年 6月 2011年 7月 2011年 8月 Sunday Monday Tuesday Wednesday
Monday, January 29, Day 105 Wow! Do we have a lot of catching up to do!!! Please enter quietly, and fill in your agenda. When you are done with.
Monday, FEBRUARY 5, Day 110 Welcome back! I hope you had a great weekend! Please enter quietly, distribute job cards, and fill in your agenda.
On and At Unit 2 Fun after school.
CSE 303 Concepts and Tools for Software Development
SPL – PS2 C++ Memory Handling.
CSE 303 Concepts and Tools for Software Development
Presentation transcript:

Manual Memory Management: Mastering malloc() CSE 333 – SECTION 2 Manual Memory Management: Mastering malloc()

Office Hours Hal Renshu Johnny Sunjay Cortney Discussion board! Mondays, 4pm-5pm (CSE 548) Or by appointment Or just drop in if the door’s open Renshu Tuesdays, 3:30pm-4:30pm (CSE 006) Johnny Wednesdays, 3:30pm-4:30pm (CSE 006) Sunjay Thursdays (that’s today!), 3:30pm-4:30pm (CSE 006) Cortney Fridays, 3:30pm-4:30pm (CSE 006) Discussion board! All day, every day

Questions, Comments, Concerns Do you have any? Exercises going ok? Lectures make sense? Looked at the homework?

Using the Heap Why is this necessary? Lifetime on the stack Lifetime on the heap

Memory Management C gives you the power to manage your own memory C does very little for you Benefits? Disadvantages? When would you want this vs. automatic memory management?

Memory Management Done Right Need to let the system know when we are done with a chunk of memory In general, every malloc() must (eventually) be matched by a free() Example: [lec04_code/arraycopy.c]

Memory Management Details When are we done with a piece of data? Depends on where we got it from, how we are using it, etc. Some functions expect allocated space, others allocate for you sprintf() vs asprintf() Some APIs expect you to free structures, others free for you Compare / contrast?

Memory Management Gone Horribly Wrong Many (many!) ways to mess up Dangling pointers Double frees Incorrect frees Never frees That’s just a few Small example: [badlylinkedlist.c]

Valgrind Is Your Friend Use of uninitialized memory Use of memory you shouldn’t be using Memory leaks Definitely Lost Indirectly Lost Possibly Lost Still Reachable* Simply run: valgrind <program> Small example: [imsobuggy.c] *This is generally ok