STL containers are neat, but you had just missed the most important part. It's a lot easy to make insertion or removal operations towards a STL container, the main point is, when and what containers should we use for a specific situation. Vector can be really very inefficient then you use it to make a lot of insertion operations, because then capacity is full, the vector allocates an entire new space of the space required, also, it copies the last block of space to the new, and finally it deletes the old block of space. You also should explicitly reserve a space after the vector declaration with vector::reserve with the appropriate space you need.
For insertion operations is much better to use a std::list, which perform insertion operations very efficiently without need to resize, because std::list is a linked list, so just creates a new node and link's it to the last. The main drawback of the std::list is the access time to an element and the extra space required to maintain a double-linked list, std::vector has this advantage over std::list because the access time is fast as an built-in array because it's allocated like an array.
Maybe i should make a tutorial about this important subject.
Edit: I didn't have seen part 2 then i was writing this, you specified std::reserve and other important subjects. So you already know part of what i'm talking about.
Last edited by outsid3r; 08-30-2009 at 04:28 AM.
Yeah, I'm actually not done with this as much as I have stopped working on it. There's at least two more parts to Vectors, and then a lot more, including lists. My very first blog entry outlines how I'll be going about teaching everything in the STL, and lists are on chapter 5. I'm trying to cover a lot of ground with these tutorials, so I'm sorry if I leave out some parts at first, I'll get to them.![]()
Wow I changed my sig!
that's great![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks