The Artima Developer Community
Sponsored Link

Python Buzz Forum
C++ tip: always use std::list, not std::deque or std::vector, if you like storing pointers or...

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Phillip Pearson

Posts: 1083
Nickname: myelin
Registered: Aug, 2003

Phillip Pearson is a Python hacker from New Zealand
C++ tip: always use std::list, not std::deque or std::vector, if you like storing pointers or... Posted: Oct 12, 2003 9:03 PM
Reply to this message Reply

This post originated from an RSS feed registered with Python Buzz by Phillip Pearson.
Original Post: C++ tip: always use std::list, not std::deque or std::vector, if you like storing pointers or...
Feed Title: Second p0st
Feed URL: http://www.myelin.co.nz/post/rss.xml
Feed Description: Tech notes and web hackery from the guy that brought you bzero, Python Community Server, the Blogging Ecosystem and the Internet Topic Exchange
Latest Python Buzz Posts
Latest Python Buzz Posts by Phillip Pearson
Latest Posts From Second p0st

Advertisement
I'm the sort of person who likes using iterators and pointers (rather than indices) to remember where I am in a list. I tend to store them in structures, then go away, modify the list, and expect them to still be valid when I come back.

That's perfectly reasonable when I'm using std::list, but it all goes to hell when using something that periodically needs reallocation. When you try to put something into a std::vector and it doesn't have space, it reallocates the whole thing and copies the old data to the new location, invalidating all your pointers.

Every time I use something other than std::list to store stuff, I end up forgetting this. And it always takes me a whole day to figure out what I've done wrong.

Oops!

Comment

Read: C++ tip: always use std::list, not std::deque or std::vector, if you like storing pointers or...

Topic: Movable Type does invalid XML-RPC? Previous Topic   Next Topic Topic: PyPI grows sqlite indexes...

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use