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
16 29398
why was my code removed???
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;;;;;; ;;;, - Removed as per posting guidelines
-
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.
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?
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
Hi all !!
Now I understand ....I am really sorry ........afteral l i am a newbie.
Ok
here is how I define my structure.... -
struct IDnTime
-
{
-
vector<char *> s;
-
vector<char *> g;
-
struct tm theTime;
-
struct tm *ptr;
-
time_t t;
-
} IDnTimeArray[50];
-
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) -
-
char Walk ='w',Bike ='b',Car ='c',UrbanPuT ='u',Rail ='r',Notdecided ='n',Activity ='a';
-
char *walk =&Walk, *bike =&Bike, *car =&Car, *urbanPuT =&UrbanPuT, *rail =&Rail, *notdecided =&Notdecided, *activity =&Activity;
-
Then i try to push back like this -
IDnTimeArray[counter1].s.push_back(&Activity);
-
IDnTimeArray[counter1].s.push_back(&Walk);
-
and so on.......76,000 character addresses in the vector 's'..and similarly for the vector g as well -
IDnTimeArray[counter1].g.push_back(&Activity);
-
IDnTimeArray[counter1].g.push_back(&Walk);
-
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 -
IDnTimeArray[counter1].s.clear();
-
IDnTimeArray[counter1].g.clear();
-
So the memory is freed......
HELP HELP
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
A bad_alloc() us an an exception thrown by C++ when it runs out of heap memory.
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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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++
|
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
|
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.
|
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,
| |
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?
|
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...
|
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...
|
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...
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |