CMPSC 32 Lecture Notes - Lecture 5: C Dynamic Memory Allocation, Iterator

64 views4 pages
26 Sep 2017
School
Course
Professor

Document Summary

Only way to change size is to copy the entire thing to a larger array. Whatever is contained in it is in angle brackets. Push things on to the end, or insert things into the middle. Syntax to add/remove/access/change things looks like array syntax. O(1) int i = v[5]; v[7] = 8; v is an lvalue. Pointers (in between way) int* x = new int[10]; v is an rvalue. Reading value on the right hand side of the equal side. Old way: int* x = (int *)malloc(10) malloc = memory allocation. Type cast x can be passed outside of scope. Heap = large amount of memory that gets written to / read. Moving around / changing pointers = garbage collection. Liveness of pointer variable is a global property. Plug in type parameters (not values, like in function calls) A type is plugged into dummy variable t. You write (almost) identical code in several places.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents