lecture14 - Last time Chapter 9 Strings Characters and...

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 14 1 CMSC 212 Lecture 14 October 15, 2009 Last time Chapter 9, Strings, Characters, and Bytes – copying and appending strings – comparing strings – searching for things in strings – length-restricted or safe versions of some string functions – writing your own string functions if needed 2 CMSC 212 Reading c Read Chapter 12 in Reek (Pointers on C) 3 CMSC 212 Chapter 11, Dynamic Memory Allocation 4 CMSC 212
Background image of page 1

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

View Full Document Right Arrow Icon
Stack and heap memory Stack memory is allocated and deallocated in a specific order – any item in a stack is always removed before the item before it stack top 5 CMSC 212 – a heap is natural for storing program local variables Heap memory – can be allocated and deallocated in any order while a program is running free space allocated space Dynamically allocated memory Why use dynamically allocated memory? – to eliminate compile-time limits: • it's hard to get sizes of things exactly right, and often the sizes of data structures needed depend on the amount of data in the input, which isn't known when the program was written • overestimation leads to wasted space omparing ser anaged memory eallocation garbage 6 CMSC 212 Comparing user-managed memory deallocation to garbage collection: – garbage collection: • less work for the programmer • slower (it takes time to run collection algorithms to free up space) – user-managed: • faster • more work for the programmer to explicitly deallocate everything • errors can occur if something still in use is incorrectly deallocated Lightweight memory management in C Allocating memory:
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.

{[ snackBarMessage ]}

Page1 / 5

lecture14 - Last time Chapter 9 Strings Characters and...

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