I thought STL containers destroyed there contents

Started by
17 comments, last by xorjesus 19 years, 10 months ago
auto_ptr is very bad for stl containers.

http://www.devx.com/tips/Tip/5480

I think one of the boost smart pointers should work.
Advertisement
no because you cant have them in a vector.
edit: auto_ptr that is

[edited by - Eriond on May 30, 2004 8:47:14 PM]
A plethora of informationt to digest. Thanx for all the informative replies. I''m really just looking for a solution where I can have an expandable type of array that holds pointers to objects. I didn''t want to have to write a Linked List. But since where I need this code will be called a 20-50 times in every main loop iteration, I believe a vector of boost::shared_ptr will be too slow. I think i''ll have to end up using a Singlely linked list :[
I study day and night, memorizing the game.
template <class Seq>void tidy(Seq& container){     typename container::iterator it;     for (it = container.begin(); it != container.end(); ++it)     {         delete *it;         *it = 0;     }}tidy(vlpA); // boom


[edited by - fallenang3l on May 30, 2004 9:06:54 PM]
not to evangelize the act of reinventing the wheel, but writing a linked list is a good exercise

... and besides, once you write it you can use it in any application you make in the future! and you''ll know exactly what it does
Greenspun's Tenth Rule of Programming: "Any sufficiently complicated C or Fortran program contains an ad-hoc, informally-specified bug-ridden slow implementation of half of Common Lisp."
I dug this up on google, it may have a good solution.

http://www.infrasoft.co.at/hn/stlcont.htm
I don''t think there will be much difference in speed between a vector of ordinary pointers and one of shared_ptr''s. Why not try it? If it''s too slow then you change it.
Some pretty performance graphs here.

http://www.boost.org/libs/smart_ptr/smarttests.htm
quote:Original post by xorjesus
I''m really just looking for a solution where I can have an expandable type of array that holds pointers to objects.


java.util....never mind

This topic is closed to new replies.

Advertisement