Re: Serious Issue With std::vector
Re: Serious Issue With std::vector
- Subject: Re: Serious Issue With std::vector
- From: Sandy Martel <email@hidden>
- Date: Mon, 5 Dec 2005 10:21:26 +1100
Here's a simpler version of the problem:
std::vector<std::vector<std::string> > v;
v.push_back( std::vector< std::string >() );
std::vector< std::string > &ref = v[0];
v.push_back( std::vector< std::string >() );
ref.push_back( "test" );
Can you spot the bug? I extract a reference from a vector, then I
modify the vector, possibly invalidating all references I had to
object inside it and then I try to use ref !
Look at your code, it does the same thing.
Sandy.
Le 05-12-05 à 09:54, Adin Hunter Baber a écrit :
Sorry for the cross post, but I thought that this post was germane
to both groups.
I ran into an error while trying to use std::vectors in my carbon
project. Apparently, something is happening when the vector tries
to allocate new memory for a push_back() call.
The gdb window that pops us says:
"Unable to disassemble __new_handler."
The stack trace shows this:
#0 0xffff8a4c in __new_handler
#1 0x000051f8 in std::__copy<true,
std::random_access_iterator_tag>::copy<int> at stl_algobase.h:300
#2 0x00006098 in std::__copy_aux<int*, int*> at stl_algobase.h:317
#3 0x0000666c in std::__copy_normal<true,
true>::copy_n<__gnu_cxx::__normal_iterator<int*, std::vector<int,
std::allocator<int> > >, __gnu_cxx::__normal_iterator<int*,
std::vector<int, std::allocator<int> > > > at stl_algobase.h:354
#4 0x00006704 in std::copy<__gnu_cxx::__normal_iterator<int*,
std::vector<int, std::allocator<int> > >,
__gnu_cxx::__normal_iterator<int*, std::vector<int,
std::allocator<int> > > > at stl_algobase.h:387
#5 0x00006780 in
std::__uninitialized_copy_aux<__gnu_cxx::__normal_iterator<int*,
std::vector<int, std::allocator<int> > >,
__gnu_cxx::__normal_iterator<int*, std::vector<int,
std::allocator<int> > > > at stl_uninitialized.h:74
#6 0x00006800 in
std::uninitialized_copy<__gnu_cxx::__normal_iterator<int*,
std::vector<int, std::allocator<int> > >,
__gnu_cxx::__normal_iterator<int*, std::vector<int,
std::allocator<int> > > > at stl_uninitialized.h:113
#7 0x0000687c in
std::__uninitialized_copy_a<__gnu_cxx::__normal_iterator<int*,
std::vector<int, std::allocator<int> > >,
__gnu_cxx::__normal_iterator<int*, std::vector<int,
std::allocator<int> > >, int> at stl_uninitialized.h:254
#8 0x00006acc in std::vector<int, std::allocator<int>
>::_M_insert_aux at vector.tcc:279
#9 0x00006d38 in std::vector<int, std::allocator<int> >::push_back
at stl_vector.h:610
#10 0x00006d94 in FileListElement::push_child at FileList.hpp:47
#11 0x0000260c in loadRootFolder at main.cpp:30
#12 0x000028dc in main at main.cpp:16
The project and minimized code can be found here http://
www.adinhunterbaber.com/downloads/FileList.tar.gz
Every time I run this test app, it fails with the above error. I
am running Xcode 2.2 on a Powerbook 12" 1.5Ghz / 768 Meg.
I have seen two other mentions of problems with the STL on the
mailing lists. And I am wondering if there is some serious glitch
in the STL implementation or gcc.
Could someone else please download the above project, and see if it
also fails for you?
Notes:
Initially the code in loadRootFolder() did not have the strings
created before passing them into calls to push_file(). However, I
found that when I tried to use the implicit cstr->string
conversion, the code would also fail when trying to allocate memory
for the string. This causes me to believe the error may be in the
std::allocator.
I've been using my own C++ classes extensively. These classes
don't use std::allocator, and thus have not exhibited any such
problems. I even implemented my own vector class, which doesn't
use std::allocator, and now my application is working as it should.
Adin Hunter Baber
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden