segmentation error in vector<vector<long> >

Z

zl2k

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?
 
V

Victor Bazarov

zl2k said:
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
 
U

utab

zl2k said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top