C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

seg-fault on vector-auto-reserve

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Matthias Kaeppler
Guest





PostPosted: Sun Feb 27, 2005 7:54 pm    Post subject: seg-fault on vector-auto-reserve Reply with quote



Hi,

I'm holding a vector of boost::filesystem::pathS and a vector of
pointers to them. I use the reserve member function on both to reserve
space for 500 files. That means, for the 501th file added, the vector
will grow to hold 1000 files right?
Well, as soon as this happens I am getting a segmentation fault. I'm
sure this is the reason, because the program crashed when I entered
/usr/bin which holds about 1700 files, and if I change the initial
capacity to 2000 instead, the program won't crash.

I'm totally lost, any idea what could cause the crash?

--
Matthias Kaeppler
Back to top
Matthias Kaeppler
Guest





PostPosted: Sun Feb 27, 2005 8:04 pm    Post subject: Re: seg-fault on vector-auto-reserve Reply with quote



Matthias Kaeppler wrote:
Quote:
Hi,

I'm holding a vector of boost::filesystem::pathS and a vector of
pointers to them. I use the reserve member function on both to reserve
space for 500 files. That means, for the 501th file added, the vector
will grow to hold 1000 files right?
Well, as soon as this happens I am getting a segmentation fault. I'm
sure this is the reason, because the program crashed when I entered
/usr/bin which holds about 1700 files, and if I change the initial
capacity to 2000 instead, the program won't crash.

I'm totally lost, any idea what could cause the crash?


I did a segfault backtrace and recognized that it happens in
std::partition invoked on the pointer-vector. Is this, because as soon
as the vector gets resized, all pointers get invalidated?

--
Matthias Kaeppler

Back to top
Victor Bazarov
Guest





PostPosted: Sun Feb 27, 2005 10:01 pm    Post subject: Re: seg-fault on vector-auto-reserve Reply with quote



"Matthias Kaeppler" <nospam (AT) digitalraid (DOT) com> wrote...
Quote:
Matthias Kaeppler wrote:
Hi,

I'm holding a vector of boost::filesystem::pathS and a vector of pointers
to them. I use the reserve member function on both to reserve space for
500 files. That means, for the 501th file added, the vector will grow to
hold 1000 files right?
Well, as soon as this happens I am getting a segmentation fault. I'm sure
this is the reason, because the program crashed when I entered /usr/bin
which holds about 1700 files, and if I change the initial capacity to
2000 instead, the program won't crash.

I'm totally lost, any idea what could cause the crash?


I did a segfault backtrace and recognized that it happens in
std::partition invoked on the pointer-vector. Is this, because as soon as
the vector gets resized, all pointers get invalidated?

Quite possible. Resizing may require reallocation. Reallocation makes
all iterators and references (and pointers) invalid.

V



Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.