Class Notes (808,549)
Canada (493,288)
CS 138 (14)
Lecture 12

Data Lecture 12.docx

2 Pages
Unlock Document

University of Waterloo
Computer Science
CS 138
Michael Godfrey

Data Lecture 12 February 4, 2013 Dynamic Arrays  Use a vector instead except fir Assignment #2  Vectors (and other library containers) are implemented using dynamic arrays  We are just looking under the hood to better understand what is going on Statically Allocated Arrays  Come from C  Storage is allocated on the stack  Array “extent” (size) must be a compile-time constant (usually) Dynamically-Allocated Arrays  C++ only  Storage allocated on heap  Array extent can be any positive integer o Checked at “instantiation” of array  Must delete[]A when done  Can’t programmatically access extent of dynamic array except by “cheating” o Instead, use instance of class vector or array  Can’t return an array from a function, but CAN return a ptr, so we do that  The run-time system needs to store the extent somewhere to know how many elements it is pointing to sot it can delete the right number of elements  Cant store extent with the pointer as it’s just an int* or string* so this would break normal pointer meaning  Can’t store the size right at the beginning of the array o Eg: a[0] would break normal array indexing arithmetic  The compiler and runtime can decide to do any number of things but the most common is to store
More Less

Related notes for CS 138

Log In


Don't have an account?

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.