Lecture 19 - Implementing Vector

Lecture 19 - Implementing Vector - Implementingvector<>...

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

View Full Document Right Arrow Icon
Implementing vector<> Lecture 26 Hartmut Kaiser [email protected] http://www.cct.lsu.edu/˜ hkaiser /fall_2011/csc1254.html  
Image of page 1

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

View Full Document Right 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
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 Higher-level operations 12/01/ 2011,  Lecture s 26 CSC1254,  Fall 2011,  Implementi ng  vector<> 3
Image of page 3

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

View Full Document Right 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
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]:
Image of page 5

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

View Full Document Right 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
Image of page 6
Vector (constructor) vector::vector( int s)
Image of page 7

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern