By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,227 Members | 1,290 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,227 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
14 Replies


P: n/a
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

P: n/a
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

P: n/a
"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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
"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

P: n/a
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

P: n/a
"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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.