473,804 Members | 3,557 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

terminate called after throwing an instance of 'std::bad_alloc ' what(): St9bad_all

upadhyad
15 New Member
Hi everyone !!

i have an interesting problem...hope you people can help.
I am coding in C.
the code is posted below:
here I have a structure with two character vectors.
I have to characters. in them depending on a text file. Arround 76,000 characters in each of them one after the other....But i am not able to do so...the program runs fine for small data...but with these 76,000 characters pushed in each vector one after the other causes the following error while runing
=============== =====
terminate called after throwing an instance of 'std::bad_alloc '
what(): St9bad_alloc
Aborted
=============== ========
am I running out of RAM .. what is the problem???
please help it is urgent!!!

Code removed, please read the posting guidelines
Jul 9 '08 #1
16 29398
upadhyad
15 New Member
why was my code removed???
Jul 9 '08 #2
upadhyad
15 New Member
The code is here::::Please do not remove this time it is urgen if you keep removing nobody will be able to see it ...thanks;;;;;; ;;;,
Expand|Select|Wrap|Line Numbers
  1. Removed as per posting guidelines
  2.  
Jul 9 '08 #3
Banfa
9,065 Recognized Expert Moderator Expert
The code is here::::Please do not remove this time it is urgen if you keep removing nobody will be able to see it
And if you read the posting guidelines as suggested in the original edit to your post you would know why your code keeps getting removed.
Jul 9 '08 #4
Banfa
9,065 Recognized Expert Moderator Expert
It rather depends on the platform you are using but 2 lots of 76000 characters is 152000 bytes of data. This is certainly within the constraints of a modern PC so that suggests that there is another problem with your code.

Before I removed your code I noticed you have vectors of char *, do you allocate memory for all those pointers before using them or at least point them at a buffer somewhere?
Jul 9 '08 #5
gpraghuram
1,275 Recognized Expert Top Contributor
Hi,
Dont post the whole code...
Post the part how u have declared the vector and how are u pushing into it.


Raghu
Jul 10 '08 #6
upadhyad
15 New Member
Hi all !!
Now I understand ....I am really sorry ........afteral l i am a newbie.
Ok
here is how I define my structure....
Expand|Select|Wrap|Line Numbers
  1. struct IDnTime 
  2.     {    
  3.         vector<char *> s;
  4.         vector<char *> g;        
  5.         struct tm theTime;
  6.         struct tm *ptr;            
  7.         time_t t;
  8.     } IDnTimeArray[50];
  9.  
Next I inititalize few char variables and then point them with the pointers like this:(this I did to avoid pushing characters themselves in the vectors....now this should allow me to push the addresses of the characters or the poiters to thode characters in the vector)
Expand|Select|Wrap|Line Numbers
  1.  
  2. char Walk ='w',Bike ='b',Car ='c',UrbanPuT ='u',Rail ='r',Notdecided ='n',Activity ='a';
  3.     char *walk =&Walk, *bike =&Bike, *car =&Car, *urbanPuT =&UrbanPuT, *rail =&Rail, *notdecided =&Notdecided, *activity =&Activity;
  4.  
Then i try to push back like this
Expand|Select|Wrap|Line Numbers
  1. IDnTimeArray[counter1].s.push_back(&Activity);
  2. IDnTimeArray[counter1].s.push_back(&Walk);
  3.  
and so on.......76,000 character addresses in the vector 's'..and similarly for the vector g as well
Expand|Select|Wrap|Line Numbers
  1. IDnTimeArray[counter1].g.push_back(&Activity);
  2. IDnTimeArray[counter1].g.push_back(&Walk);
  3.  
the program compiles fine...gr8..the n I run it ..it runs for 2 or three seconds ...gr8...then as the pushing back operation in the 's' vector of the array of the structures is completed and the g vector is started it stops .....when I run it on my computer the process it terminated here is

terminate called after throwing an instance of 'std::bad_alloc '
what(): St9bad_all
Aborted



i dont get this .....PLEASE HELPi dont get this .....PLEASE HELP

Also few may ask whether I try to fill all the 's' and 'g' vectors of the 50 structure array locations together.......
the answer is NO!...first I approach each structure array element and then i try to fill the s and g vectors of that location(whch is not allowed and the message displayed i mentioned above)...then as i finsh my desired function with these vectors I clear these vectors by
Expand|Select|Wrap|Line Numbers
  1. IDnTimeArray[counter1].s.clear();
  2. IDnTimeArray[counter1].g.clear();
  3.  
So the memory is freed......

HELP HELP
Jul 10 '08 #7
upadhyad
15 New Member
It rather depends on the platform you are using but 2 lots of 76000 characters is 152000 bytes of data. This is certainly within the constraints of a modern PC so that suggests that there is another problem with your code

the platform used is ubuntu terminal
Jul 10 '08 #8
weaknessforcats
9,208 Recognized Expert Moderator Expert
A bad_alloc() us an an exception thrown by C++ when it runs out of heap memory.
Jul 10 '08 #9
upadhyad
15 New Member
whn I try to push back just one of the vectors and comenting out the pushing back in the g vector the process works fine....and similarly for the g vector.
where can be the problem ???
I tried it with the vector resize option also....but it did not work either
Jul 10 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2863
by: Jacek Dziedzic | last post by:
Hi! I accidentally did something like float *ptr = new float; where n was accidentally left uninitialized (and equal to something like -1073372080) and my program coredumped. I always thought that new was supposed to throw bad_alloc
5
2183
by: Asfand Yar Qazi | last post by:
Hi, Just wondering, if I do a: std::set_new_handler(std::terminate) I won't have to worry about a std::bad_alloc being thrown when I do a 'new ...' or a 'new(nothrow) ...', right? Its just that I'm writing a Ruby extension, and I tried wrapping C++
5
55916
by: Gary Wessle | last post by:
Hi I am getting this error when running a very similar code like the below, it is made for illustration only. thanks *************************************** **************** error **************** (gdb) n
14
29140
by: Mohsen | last post by:
Hello everyone, In my program, I have to define many pointers and when I want to compile my program (in UNIX), it gives me the following error: terminate called after throwing an instance of 'std::bad_alloc' what(): St9bad_alloc Abort I rechecked those pointers; I found I cannot decrease the size of them.
3
18112
by: schizoid_man | last post by:
Hi, I have the following code snippets and I get a std::bad_alloc error where I think there should be none. I've attached the relevant bits of the base class, derived class and the .cpp file containing the main() method. I'd really appreciate any help in getting this error sorted out. Thanks,
4
2999
by: sndive | last post by:
Do linux kernels 2.4 and 2.6 have some stash of memory set aside to handle paging in std::bad_alloc or ... exception handling code when new or new throws that exception? How is that handled? Does gcc generate some report to the elf loader that the largest exception handling section is x kb long or what?
4
13099
by: Alerion | last post by:
Hello everyone, I've been a regular of this forum but this is my first post, generally I can find the answer to my question already, but this time I'm having a somewhat specific problem. For fun I've been working on making a 3d game (who hasn't haha) and while it's nothing special at the moment I was making some decent headway. I'm working on constructing an octree for my triangle data, but I keep getting this pesky bad_alloc runtime...
7
1927
by: =?Utf-8?B?U3RldmVa?= | last post by:
First off, I am not sure if this belongs in this group or the C# group. It seems more like a C++ problem to me. Anyways... I have a C# project which links in an unmanaged C++ DLL, both built with VS2005. I am having a problem where the C# program is making a call into the C++ DLL which new's a large class. For a class of a certain size the new is failing. Here's somewhat of an example of what I am doing: // Start C# program code...
0
10583
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10337
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10323
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9160
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7622
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4301
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3822
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2995
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.