10_Memory_and_Valgrind

10_Memory_and_Valgrind - Discussion 10: Memory and Valgrind...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the 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.

Page1 / 4

10_Memory_and_Valgrind - Discussion 10: Memory and Valgrind...

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

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