473,397 Members | 2,099 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,397 software developers and data experts.

terminate called after throwing an instance of 'std::bad_alloc'

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.
Any idea how I can to solve this problem?

Thanks,
Mohsen

Nov 7 '06 #1
14 29081
Mohsen wrote:
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.
Any idea how I can to solve this problem?
Are you saying your compiler terminates? If so, ask your compiler
vendor.

If you are talking about your program, then you don't have sufficient
memory to allocate whatever you are trying to allocate. If you can't
decrease the size of what you are allocating (or otherwise provide
enough space) and can't add more memory to your computer, then you're
sunk.

Cheers! --M

Nov 7 '06 #2
Mohsen wrote:
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.
Any idea how I can to solve this problem?
Without seeing your code it's impossible to tell what is going on.

I have no idea what you mean by "cannot decrease the size".
Nov 7 '06 #3
"Mohsen" <ja*******@gmail.comwrote:
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
During the compile, or while your program is running?

--
To send me email, put "sheltie" in the subject.
Nov 7 '06 #4
it happens during the compile.

Daniel T. wrote:
"Mohsen" <ja*******@gmail.comwrote:
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

During the compile, or while your program is running?

--
To send me email, put "sheltie" in the subject.
Nov 7 '06 #5
Mohsen wrote:
it happens during the compile.
To reiterate: "Are you saying your compiler terminates? If so, ask your
compiler vendor." Or you could ask on a newsgroup dedicated to your
compiler. See:

http://www.parashift.com/c++-faq-lit...t.html#faq-5.9

Cheers! --M

PS, Please don't top-post here (see
http://www.parashift.com/c++-faq-lit....html#faq-5.4).

Nov 7 '06 #6
Mohsen:
it happens during the compile.

First guess would be that your compiler is running out of memory. Try closing
as many applications as possible, then try re-compile.

Second guess would be that your compiler is broken... but I don't see how a
bug could result in the throwing of a bad_alloc.

--

Frederick Gotham
Nov 7 '06 #7
Frederick Gotham wrote:
but I don't see how a
bug could result in the throwing of a bad_alloc.
int main()
{
for( ;; ) int *p = new int;
}

Cheers! --M

Nov 7 '06 #8
mlimber:
>but I don't see how a
bug could result in the throwing of a bad_alloc.

int main()
{
for( ;; ) int *p = new int;
}

Touché!

--

Frederick Gotham
Nov 7 '06 #9
mlimber wrote:
Frederick Gotham wrote:
>but I don't see how a
bug could result in the throwing of a bad_alloc.

int main()
{
for( ;; ) int *p = new int;
}

Cheers! --M
Compiles fine on mine!
--
Bill Medland
Nov 7 '06 #10
Bill Medland:
Compiles fine on mine!
Because that's the code your compiling, as opposed to the source code of the
compiler.

--

Frederick Gotham
Nov 7 '06 #11
"mlimber" <ml*****@gmail.comwrote:
Frederick Gotham wrote:
but I don't see how a
bug could result in the throwing of a bad_alloc.

int main()
{
for( ;; ) int *p = new int;
}
That won't cause the *compiler* to throw a bad_alloc.

--
To send me email, put "sheltie" in the subject.
Nov 7 '06 #12
Daniel T.:
That won't cause the *compiler* to throw a bad_alloc.

It will if it's part of the compiler's source code.

--

Frederick Gotham
Nov 7 '06 #13
"Mohsen" <ja*******@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
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.
Any idea how I can to solve this problem?

Thanks,
Mohsen
You say it's happening when you are tryign to compile, not run your program.
The first thing I would do would attempt to get a newer version of the
compiler. If that didnt' work, I would google for my compiler name and
"bad_alloc" and see if I got any hits. If that didnt' work I"d post in a
newsgroup for my compiler.
Nov 8 '06 #14
Jim Langston wrote:
"Mohsen" <ja*******@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
>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.
Any idea how I can to solve this problem?

Thanks,
Mohsen

You say it's happening when you are tryign to compile, not run your program.
The first thing I would do would attempt to get a newer version of the
compiler. If that didnt' work, I would google for my compiler name and
"bad_alloc" and see if I got any hits. If that didnt' work I"d post in a
newsgroup for my compiler.
What does the standard say about recursive templates? For instance, g++
3.4.4 issues a reasonable diagnostic with the following, but is it
required to? Seems like this could be something that might cause a
compiler to throw std::bad_alloc.

template <unsigned long N>
class A
{
public:

static const unsigned long a = A<N+1>::a;
};

int main()
{
unsigned long i = A<0>::a;
}

Nate
Nov 8 '06 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
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...
21
by: Stephan | last post by:
why does the following code not work???? after compiling and running it will just say killed after all my memory filled up any suggestions? #include <iostream> using namespace std; void...
5
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...
3
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...
4
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...
3
by: jyothiusha | last post by:
terminate called after throwing an instance of 'std::bad_alloc' what(): St9bad_alloc Aborted could anyone help me in this? //mst.cpp #include <iostream> #include <fstream>
4
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...
16
upadhyad
by: upadhyad | last post by:
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....
4
by: Kaio Vieira | last post by:
Hello, I have a "std::bad_alloc" problem when I try to run a simple C++ program on HP-UX. I don't know if it is a memory limitation or maybe a compiler option that I should use. When my program...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.