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

Discussion in 'C++' started by Mohsen, Nov 7, 2006.

  1. Mohsen

    Mohsen Guest

    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
     
    Mohsen, Nov 7, 2006
    #1
    1. Advertising

  2. Mohsen

    mlimber Guest

    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
     
    mlimber, Nov 7, 2006
    #2
    1. Advertising

  3. 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".
     
    Gianni Mariani, Nov 7, 2006
    #3
  4. Mohsen

    Daniel T. Guest

    "Mohsen" <> wrote:

    > 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.
     
    Daniel T., Nov 7, 2006
    #4
  5. Mohsen

    Mohsen Guest

    it happens during the compile.

    Daniel T. wrote:
    > "Mohsen" <> wrote:
    >
    > > 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.
     
    Mohsen, Nov 7, 2006
    #5
  6. Mohsen

    mlimber Guest

    mlimber, Nov 7, 2006
    #6
  7. 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
     
    Frederick Gotham, Nov 7, 2006
    #7
  8. Mohsen

    mlimber Guest

    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
     
    mlimber, Nov 7, 2006
    #8
  9. 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
     
    Frederick Gotham, Nov 7, 2006
    #9
  10. Mohsen

    Bill Medland Guest

    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
     
    Bill Medland, Nov 7, 2006
    #10
  11. Bill Medland:

    > Compiles fine on mine!


    Because that's the code your compiling, as opposed to the source code of the
    compiler.

    --

    Frederick Gotham
     
    Frederick Gotham, Nov 7, 2006
    #11
  12. Mohsen

    Daniel T. Guest

    "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;
    > }


    That won't cause the *compiler* to throw a bad_alloc.

    --
    To send me email, put "sheltie" in the subject.
     
    Daniel T., Nov 7, 2006
    #12
  13. 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
     
    Frederick Gotham, Nov 7, 2006
    #13
  14. Mohsen

    Jim Langston Guest

    "Mohsen" <> wrote in message
    news:...
    > 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.
     
    Jim Langston, Nov 8, 2006
    #14
  15. Mohsen

    Nate Barney Guest

    Jim Langston wrote:
    > "Mohsen" <> wrote in message
    > news:...
    >> 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
     
    Nate Barney, Nov 8, 2006
    #15
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jacek Dziedzic

    new not throwing bad_alloc

    Jacek Dziedzic, Jul 29, 2003, in forum: C++
    Replies:
    3
    Views:
    697
    Kevin Goodsell
    Jul 30, 2003
  2. Gary Wessle

    std::bad_alloc

    Gary Wessle, Aug 14, 2006, in forum: C++
    Replies:
    5
    Views:
    7,822
    peter koch
    Aug 15, 2006
  3. Daniel Fetchinson
    Replies:
    0
    Views:
    209
    Daniel Fetchinson
    Oct 2, 2012
  4. Peter Otten
    Replies:
    0
    Views:
    210
    Peter Otten
    Oct 2, 2012
  5. Daniel Fetchinson
    Replies:
    0
    Views:
    205
    Daniel Fetchinson
    Oct 2, 2012
Loading...

Share This Page