lecture18 - Last time Make Introduction to Low-Level...

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

View Full Document Right Arrow Icon
Introduction to Low-Level Programming Concepts CMSC 212 ecture 18 1 CMSC 212 Lecture 18 October 29, 2009 Last time Make – additional features of make Section 10.9 (Bryant & O'Hallaron), Dynamic memory allocation – implementing heap allocation – requirements and goals for the heap manager 2 CMSC 212 – a simple data structure that can be used for a heap – coalescing in free() – an alternative to fixed-size heap blocks featuring explicit free lists Reading Read Chapter 15 in Reek (Pointers on C) 3 CMSC 212 Dynamic Memory Allocation (Section 10.9, Bryant & 4 CMSC 212 O'Hallaron), con't.
Background image of page 1

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

View Full DocumentRight Arrow Icon
How to make heaps safer Auxiliary tag (header) storage To enable detecting when programs write beyond the boundaries of an allocated chunk of memory, add a preamble and trailer to each allocated block containing specific bit patterns – have the memory allocation routines allocate 2 * Y bytes 5 CMSC 212 extra for each allocation request – fill the first and last Y bytes with a known nonzero bit pattern – return a pointer Y bytes into the allocated region – when a region is free() 'd, or when the user requests it, verify the Y bytes at the start and end of the region haven't been changed (Nonstandard) gcc facilities for heap inspection and debugging Heap inspection functions – to use these, #include <malloc.h> void malloc_stats(void); • prints a summary of information about the heap, including the memory currently available and allocated truct allinfo allinfo void); 6 CMSC 212 struct mallinfo mallinfo(void); • the uordblks field of a struct mallinfo contains the current total allocated space • the fordblks field contains the current total free space gcc facilities for heap inspection and debugging, con't. Facilities for automatically checking heap integrity – use gcc's –lmcheck option, or just set the environment variable MALLOC_CHECK_ to 1 before running a program, as in the UNIX command setenv MALLOC_CHECK_ 1 ese will turn on checking of the memory in the heap when 7 CMSC 212 – these will turn on checking of the memory in the heap when the memory allocation functions are invoked, that can detect certain kinds of errors and print a message if they occurred gcc facilities for heap inspection and debugging, con't. Facilities for manually checking heap integrity – to use these, #include <mcheck.h> – call the mcheck(NULL) function initially (before any memory allocations) • this turns on the same checks performed in automatic checking, but it also allows calling
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 6

lecture18 - Last time Make Introduction to Low-Level...

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