473,396 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

segmentation error in vector<vector<long> >

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
2 2214
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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Matt Garman | last post by:
What is the "best" way to copy a vector of strings to an array of character strings? By "best", I mean most elegantly/tersely written, but without any sacrifice in performance. I'm writing an...
3
by: Juicer_X | last post by:
Hello everyone, I've been working with the STL Containers for a little while now, but in the middle of working on a small "Markov Chain" class I realized that I wanted to modify my frequency...
20
by: Anonymous | last post by:
Is there a non-brute force method of doing this? transform() looked likely but had no predefined function object. std::vector<double> src; std::vector<int> dest; ...
3
by: kuiyuli | last post by:
I'm using VC++ .Net to do a simlple program. I tried to use <vector> <list> in the program, and I simply put the folowing lines " #include <list> #include <vector> #include <string> using...
2
by: danielhdez14142 | last post by:
Some time ago, I had a segment of code like vector<vector<int example; f(example); and inside f, I defined vector<int>'s and used push_back to get them inside example. I got a segmentation...
32
by: T. Crane | last post by:
Hi, I'm struggling with how to initialize a vector<vector<double>> object. I'm pulling data out of a file and storing it in the vector<vector<double>object. Because any given file will have a...
5
by: Etrex | last post by:
Hello, This is my first attempt at a c++ program, and it is a long post, please bear with me. I'm trying to read in a text file containing a firewall log, make the information...
18
by: subramanian100in | last post by:
Consider a class that has vector< pair<int, string>* c; as member data object. I need to use operator>to store values into this container object and operator<< to print the contents of the...
42
by: barcaroller | last post by:
In the boost::program_options tutorial, the author included the following code: cout << "Input files are: " << vm.as< vector<string() << "\n"; Basically, he is trying to print a vector...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.