This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: Discussion 10: Memory and Valgrind EECS 280 Monday, November 14th, 2011 1 Introduction There are several common ways that you can write code that misbehaves with respect to memory management. This week well go over a few of them and then look at a few demonstrations of a tool called Valgrind that can detect many of these errors as soon as they happen, rather then when they start to cause problems. 2 Types of Memory Problems 2.1 Pointer Initialization What happens if we run the following: // ... int* p; *p += 1; // ... Best Case Segmentation violation (segfault) Worst Case Undefined behavior! What happens if we run the following: // ... int* p = NULL; *p += 1; // ... Every Case Segmentation violation 1 2.2 Segfault is Your Friend Segmentation violations are certainly annoying to receive. However, it is better to have a segfault early on in your code rather than undefined and hard-to- reproduce behavior later on in your code....
View Full Document
This note was uploaded on 04/07/2012 for the course EECS 280 taught by Professor Noble during the Fall '08 term at University of Michigan.
- Fall '08