Re: multiset segfault
From: Joaquín Mª López Muñoz (joaquin_at_tid.es)
Date: 06/17/04
- Next message: Arthur J. O'Dwyer: "Re: multiset segfault"
- Previous message: Rolf Magnus: "Re: Initialization: = or () ?"
- In reply to: Arthur J. O'Dwyer: "Re: multiset segfault"
- Next in thread: P.J. Plauger: "Re: multiset segfault"
- Reply: P.J. Plauger: "Re: multiset segfault"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 17 Jun 2004 18:19:15 +0200
"Arthur J. O'Dwyer" ha escrito:
[...]
> > > Meanwhile, I'm still wondering what's wrong with my use of
> > > 'multiset'...
> >
> > Ummm... The problem lies in that you're storing pointers to a
> > *vector* inside myStrHash. But these pointers are *not* stable,
>
> Oh, bother! See, I knew it was something simple... :(
>
> > the elements inside myVector will be relocated when its size
> > grows; in your code this happens at about the second insertion.
> > You have two solutions:
> >
> > 1. Use an std::list insiead of an std::vector. std::list references
> > are stable, i.e elements won't be relocated over time.
>
> Aha. This would be the easiest solution, then. Thanks.
> For future reference, are there any other STL containers for
> which the elements' addresses are guaranteed to be stable?
> And I seem to recall that in a std::vector, the elements are
> guaranteed to be in contiguous memory --- but this is not true
> of std::list --- is it true of any other containers?
std::vector is the only container guaranteeing that elements
are in contiguous memory.
>
>
> I've been relying mostly on the Dinkum C++ library reference
> page and on Google for my STL information. Do you have any
> suggestions of a better STL reference for the casual C++ user?
> [Read: one that might manage to warn me about dumb mistakes like
> that one.]
>
Well,
* C++ FAQ Lite (http://www.parashift.com/c++-faq-lite/) contains
some sections on STL containers, and it is anyway worth reading the
whole contents even if not specifically dealing with STL.
* The reference at cppreference (http://www.cppreference.com/cpp_stl.html)
is a little more readable than Dinkumware's stuff.
* Thinking in C++ (http://www.bruceeckel.com/) is a C++ programming
guide downloadable for free. Vol II has some stuff on STL.
In general, if you google for "STL tutorial" you'll find many more
links. Beware to check the date of the docs you're reading: if it
is prior to 1998 (when the standard was published) then you'd rather
not use it, much info will be outdated.
HTH
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
- Next message: Arthur J. O'Dwyer: "Re: multiset segfault"
- Previous message: Rolf Magnus: "Re: Initialization: = or () ?"
- In reply to: Arthur J. O'Dwyer: "Re: multiset segfault"
- Next in thread: P.J. Plauger: "Re: multiset segfault"
- Reply: P.J. Plauger: "Re: multiset segfault"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|