By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,502 Members | 1,204 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,502 IT Pros & Developers. It's quick & easy.

segmentation error in vector<vector<long> >

P: n/a
hi, all
I am using a 2 dimensioanl array implemented by vector<vector<long> >.
When the row number grows to 8 and I am trying to insert a new row, I
got the segmentation error. However, if I reserve the row number to 16
(in my case the size of row will always less than 16) at the very
begining, then everything works well. (The column number could be quite
large.)
What is the problem? The vector can automatically grow as needed,
right? (actually, I do see it grow from 0, 1, 2, 4 and 8) Then why it
causes the segmentation error?

Jun 7 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
zl2k wrote:
I am using a 2 dimensioanl array implemented by vector<vector<long> >.
When the row number grows to 8 and I am trying to insert a new row, I
got the segmentation error. However, if I reserve the row number to 16
(in my case the size of row will always less than 16) at the very
begining, then everything works well. (The column number could be
quite large.)
What is the problem? The vector can automatically grow as needed,
right? (actually, I do see it grow from 0, 1, 2, 4 and 8) Then why it
causes the segmentation error?


Segmentation error is but one manifestation of undefined behaviour.
Read FAQ 5.8 and follow its recommendations.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 7 '06 #2

P: n/a

zl2k wrote:
hi, all
I am using a 2 dimensioanl array implemented by vector<vector<long> >.
When the row number grows to 8 and I am trying to insert a new row, I
got the segmentation error. However, if I reserve the row number to 16
(in my case the size of row will always less than 16) at the very
begining, then everything works well. (The column number could be quite
large.)
What is the problem? The vector can automatically grow as needed,
right? (actually, I do see it grow from 0, 1, 2, 4 and 8) Then why it
causes the segmentation error?


I f you show some code, you can get more help easily.

Segmentation fault occurs when the program tries to reach an undefined
block of memory. If you are using a debugger, try by setting some
breakpoints. Maybe that could help.

Regards

Jun 7 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.