 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Matthias Kaeppler Guest
|
Posted: Sun Feb 27, 2005 7:54 pm Post subject: seg-fault on vector-auto-reserve |
|
|
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
|
Posted: Sun Feb 27, 2005 8:04 pm Post subject: Re: seg-fault on vector-auto-reserve |
|
|
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
|
Posted: Sun Feb 27, 2005 10:01 pm Post subject: Re: seg-fault on vector-auto-reserve |
|
|
"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 |
|
 |
|
|
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
|
|