Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #10405 > unrolled thread
| Started by | sravanreddy001 <sravanreddy001@gmail.com> |
|---|---|
| First post | 2011-09-22 12:48 -0700 |
| Last post | 2011-09-23 00:20 -0500 |
| Articles | 8 — 5 participants |
Back to article view | Back to comp.lang.c++
Vector push_back() giving SIGSEGV error sravanreddy001 <sravanreddy001@gmail.com> - 2011-09-22 12:48 -0700
Re: Vector push_back() giving SIGSEGV error Paavo Helde <myfirstname@osa.pri.ee> - 2011-09-22 15:26 -0500
Re: Vector push_back() giving SIGSEGV error sravanreddy001 <sravanreddy001@gmail.com> - 2011-09-22 17:17 -0700
Re: Vector push_back() giving SIGSEGV error Ian Collins <ian-news@hotmail.com> - 2011-09-23 13:54 +1200
Re: Vector push_back() giving SIGSEGV error Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-09-23 09:24 +0000
Re: Vector push_back() giving SIGSEGV error Victor Bazarov <v.bazarov@comcast.invalid> - 2011-09-22 16:30 -0400
Re: Vector push_back() giving SIGSEGV error sravanreddy001 <sravanreddy001@gmail.com> - 2011-09-22 17:20 -0700
Re: Vector push_back() giving SIGSEGV error Paavo Helde <myfirstname@osa.pri.ee> - 2011-09-23 00:20 -0500
| From | sravanreddy001 <sravanreddy001@gmail.com> |
|---|---|
| Date | 2011-09-22 12:48 -0700 |
| Subject | Vector push_back() giving SIGSEGV error |
| Message-ID | <29403061.2519.1316720927293.JavaMail.geo-discussion-forums@yqaa12> |
Hi,
I've the below piece of code. I'm collecting all the links in text_files.
This code worked fine for the first 26 files and giving this error for 27th
When I skip 27th file using continue, its giving error at 89, and also at..
121 122 131.
For all the other files also. this piece of code is being executed.
When i traced it using (eclipse) i think this is because, the memory is not being alloted to this vector.
Additional Information:
I'm using around 6-7 other vector<string> objects to store other information.
And all these will have a max of 1 MB data all of them combined. and these vectors are recreated in the loop.
Could this be because, i'm not erasing the contents of vector. I don't think this is the reason.
Any inputs will be very helpful..
while(begin != string::npos && end != string::npos){
string link = line.substr(begin+2,end-begin-2);
try{
Links.push_back(link);
}
catch(...){
printf("%d - ",Links.size());
}
File_Content.push_back("L: "+link);
//printf("%s\n", line.substr(begin+2,end-begin-2).c_str());
begin = line.find("[[",end);
end = line.find("]]",begin+2);
//begin = end+1; // can be end+2, but end+1 for safety
}
Thanks,
Sravan.
[toc] | [next] | [standalone]
| From | Paavo Helde <myfirstname@osa.pri.ee> |
|---|---|
| Date | 2011-09-22 15:26 -0500 |
| Message-ID | <Xns9F68EE6A3EE40myfirstnameosapriee@216.196.109.131> |
| In reply to | #10405 |
sravanreddy001 <sravanreddy001@gmail.com> wrote in news:29403061.2519.1316720927293.JavaMail.geo-discussion-forums@yqaa12: > Hi, > I've the below piece of code. I'm collecting all the links in > text_files. > > This code worked fine for the first 26 files and giving this error for > 27th When I skip 27th file using continue, its giving error at 89, and > also at.. 121 122 131. > > For all the other files also. this piece of code is being executed. > > When i traced it using (eclipse) i think this is because, the memory > is not being alloted to this vector. There is no word 'vector' in your code. Please post a complete and compilable example demonstrating the problem. There are no obvious errors in the provided code snippet, so the problem is probably elsewhere. hth Paavo
[toc] | [prev] | [next] | [standalone]
| From | sravanreddy001 <sravanreddy001@gmail.com> |
|---|---|
| Date | 2011-09-22 17:17 -0700 |
| Message-ID | <7524880.1452.1316737057158.JavaMail.geo-discussion-forums@yqmw31> |
| In reply to | #10410 |
Hi Paavo,
<My apologies, I overlooked my question and missed the core part>
Please let me know if you need more info.
{I'm not a newbie to C++ (may be Intermediate), I checked if its refereing any out-of-bound reference etc.}
The "Links" is a vector<string> object.
The problem is:
The size of link has reached its capacity for a size of 4. (during one of the(26th) iterations of this code.)
When I'm trying to add the fifth element to the above vector, it is supposed to increase the size and add this element. But instead it is giving a SIGSEGV error.
True. There are no obvious errors.
Simply put.
I've a vector, and I was able to add 4 objects to it, and I checked that its capacity is 4. and max_size() is over a 100,000. When I'm trying to add 5th element its returning the Termination Interrupt
[toc] | [prev] | [next] | [standalone]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Date | 2011-09-23 13:54 +1200 |
| Message-ID | <9e277aF9j7U1@mid.individual.net> |
| In reply to | #10412 |
On 09/23/11 12:17 PM, sravanreddy001 wrote:
Please keep the context of the message you are replying to, otherwise
your posts don't make sense.
> Hi Paavo,
>
> <My apologies, I overlooked my question and missed the core part>
>
> Please let me know if you need more info.
> {I'm not a newbie to C++ (may be Intermediate), I checked if its refereing any out-of-bound reference etc.}
>
> The "Links" is a vector<string> object.
>
> The problem is:
> The size of link has reached its capacity for a size of 4. (during one of the(26th) iterations of this code.)
>
> When I'm trying to add the fifth element to the above vector, it is supposed to increase the size and add this element. But instead it is giving a SIGSEGV error.
>
> True. There are no obvious errors.
>
> Simply put.
> I've a vector, and I was able to add 4 objects to it, and I checked that its capacity is 4. and max_size() is over a 100,000. When I'm trying to add 5th element its returning the Termination Interrupt
You really should do what Paavo and Victor suggested and build a
complete, self-contained example demonstrating your problem that you can
post. Odds are that if you can't, your problem lies elsewhere.
--
Ian Collins
[toc] | [prev] | [next] | [standalone]
| From | Jorgen Grahn <grahn+nntp@snipabacken.se> |
|---|---|
| Date | 2011-09-23 09:24 +0000 |
| Message-ID | <slrnj7ok1n.1bk.grahn+nntp@frailea.sa.invalid> |
| In reply to | #10412 |
On Fri, 2011-09-23, sravanreddy001 wrote: > When I'm trying to add the fifth element to the above vector, it is > supposed to increase the size and add this element. But instead it is > giving a SIGSEGV error. Then debug the core dump to see where the crash happens. If it is in new/malloc(), you have corrupted the heap memory somewhere else in your code. Also, run valgrind if it exists for your platform. /Jorgen -- // Jorgen Grahn <grahn@ Oo o. . . \X/ snipabacken.se> O o .
[toc] | [prev] | [next] | [standalone]
| From | Victor Bazarov <v.bazarov@comcast.invalid> |
|---|---|
| Date | 2011-09-22 16:30 -0400 |
| Message-ID | <j5g5s9$3bt$1@dont-email.me> |
| In reply to | #10405 |
On 9/22/2011 3:48 PM, sravanreddy001 wrote:
> Hi,
> I've the below piece of code. I'm collecting all the links in text_files.
What's "text_files"? Is that the name of the variable?
> This code worked fine for the first 26 files and giving this error for 27th
> When I skip 27th file using continue, its giving error at 89, and also at..
> 121 122 131.
>
> For all the other files also. this piece of code is being executed.
>
> When i traced it using (eclipse) i think this is because, the memory is not being alloted to this vector.
Huh?
>
> Additional Information:
> I'm using around 6-7 other vector<string> objects to store other information.
> And all these will have a max of 1 MB data all of them combined. and these vectors are recreated in the loop.
>
> Could this be because, i'm not erasing the contents of vector. I don't think this is the reason.
>
> Any inputs will be very helpful..
>
>
> while(begin != string::npos&& end != string::npos){
> string link = line.substr(begin+2,end-begin-2);
> try{
> Links.push_back(link);
> }
> catch(...){
> printf("%d - ",Links.size());
> }
> File_Content.push_back("L: "+link);
> //printf("%s\n", line.substr(begin+2,end-begin-2).c_str());
> begin = line.find("[[",end);
> end = line.find("]]",begin+2);
> //begin = end+1; // can be end+2, but end+1 for safety
> }
Not enough information. For instance, how is 'File_Content' declared?
How is 'Links' declared?
Create a test setup in which program would take your 27th file only and
parse it (parsing is what you're doing, yes?) See if it fails then.
IOW, try to debug your program. Oh, and read the FAQ 5.8.
V
--
I do not respond to top-posted replies, please don't ask
[toc] | [prev] | [next] | [standalone]
| From | sravanreddy001 <sravanreddy001@gmail.com> |
|---|---|
| Date | 2011-09-22 17:20 -0700 |
| Message-ID | <24413169.2026.1316737204180.JavaMail.geo-discussion-forums@yqjw35> |
| In reply to | #10411 |
My data is fetched from text files *.txt It was running properly for upto 26 iterations(files) The vector is not cumulative. (Its created for each iteration and result used elsewhere) There is lot of memory on my machine. (The total amount of RAM that my application at any point wont be more that 5 MB)
[toc] | [prev] | [next] | [standalone]
| From | Paavo Helde <myfirstname@osa.pri.ee> |
|---|---|
| Date | 2011-09-23 00:20 -0500 |
| Message-ID | <Xns9F6954D2C5275myfirstnameosapriee@216.196.109.131> |
| In reply to | #10413 |
sravanreddy001 <sravanreddy001@gmail.com> wrote in news:24413169.2026.1316737204180.JavaMail.geo-discussion-forums@yqjw35: > My data is fetched from text files *.txt > > It was running properly for upto 26 iterations(files) > > The vector is not cumulative. (Its created for each iteration and > result used elsewhere) > > There is lot of memory on my machine. > > (The total amount of RAM that my application at any point wont be more > that 5 MB) > So? Lack of memory should give you a std::bad_alloc exception anyway, not SIGSEGV. You continue claiming that the shortage of memory in your computer is not the cause of the problem - this is most probably right, but does not help in solving the actual problem in any way. Paavo
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c++
csiph-web