Lecture 19 - Implementing Vector

Lecture 19 - Implementing Vector -...

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

View Full Document Right Arrow Icon
Implementing vector<> Lecture 26 Hartmut Kaiser hkaiser@cct.lsu.edu http://www.cct.lsu.edu/˜ hkaiser /fall_2011/csc1254.html  
Background image of page 1

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

View Full DocumentRight Arrow Icon
Vector Vector is the most useful container Simple Compactly stores elements of a given type Efficient access Expands to hold any number of elements Optionally range-checked access How is that done? That is, how is vector implemented? 12/01/ 2011,  Lecture s 26 CSC1254,  Fall 2011,  Implementi ng  vector<> 2
Background image of page 2
Building from the ground up The hardware provides memory and addresses Low level Untyped Fixed-sized No checking As fast as the hardware architects can make it The application builder needs something like a  vector 12/01/ 2011,  Lecture s 26 CSC1254,  Fall 2011,  Implementi ng  vector<> 3
Background image of page 3

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

View Full DocumentRight Arrow Icon
Building from the ground up At the lowest level, close to the hardware, life’s  simple and brutal You have to program everything yourself You have no type checking to help you Run-time errors are found when data is corrupted  or the program crashes We want to get to a higher level as quickly as we  can To become productive and reliable 12/01/ 2011,  Lecture s 26 CSC1254,  Fall 2011,  Implementi ng  vector<> 4
Background image of page 4
Vector A vector Can hold an arbitrary number of elements Up to whatever physical memory and the operating  system can handle That number can vary over time E.g. by using push_back() Example: vector< double > age(4); 12/01/ 2011,  Lecture s 26 CSC1254,  Fall 2011,  Implementi ng  vector<> 5 4 0.33 22.0 27.2 54.2 age: age[0]:   age[1]:     age[2]:    age[3]:
Background image of page 5

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

View Full DocumentRight Arrow Icon
Vector // a very simplified vector of doubles (like // vector<double>): class vector { int sz; // the number of elements (“the size”) double * elem; // pointer to the first element public : 12/01/ 2011,  Lecture s 26 CSC1254,  Fall 2011,  Implementi ng  vector<> 6
Background image of page 6
Vector (constructor) vector::vector( int s) // vector's constructor : sz(s), // store the size s in sz
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 25

Lecture 19 - Implementing Vector -...

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

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