Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
Forum Update on Monday, May 27th 2025

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

Scheduled Pinned Locked Moved Solved General and Desktop
qtimermemoryallocators
3 Posts 2 Posters 4.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    ForestPoem
    wrote on last edited by
    #1

    QTimer timer = new QTimer(this);
    timer->start(1000);
    connect(timer,SIGNAL(timeout()),this,SLOT(updateTimer()));

    Every 1 second, function works.
    my system the linux. Runs suddenly dies.

    -----global-------
    static int arrayNum[33000];
    -------------------
    

    updateTimer(){
    unsigned short int** US_INT;
    US_INT= new unsigned short int*[255];
    for(int i = 0; i < 255; i++)
    {
    US_INT[i] = new unsigned short int[128];
    memset(US_INT[i], 0, sizeof(unsigned short int) * 128);
    }
    double x;
    double y;
    int cnt= 0;
    int nArrayCount=0;
    for(int i = 0; i < 255; i++)
    {

                for(int j=0;j<128;j++){
    
                    x=j;
    y=cnt
                    nArray[nArrayCount]=US_INT[i][j];
    
                    nArrayCount++;
    
                }
                cnt=cnt+(256/255); 
    
            }
    
    
     for(int i = 0; i < 255; i++)
            {
                delete US_INT[i];
            }
    
            delete[] US_INT;
    

    }
    program stop. and message↓
    terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      It might be one of you new statements
      you can try

      try {
      code using new
      }
      catch (const std::bad_alloc&) {
      qDebug() << "alloc error";
      }

      also the arrayNum[33000];
      what do u u do with it?
      You use nArray in function. is that arrayNum ?

      1 Reply Last reply
      1
      • F Offline
        F Offline
        ForestPoem
        wrote on last edited by
        #3

        @ForestPoem said:

        nArray

        thanks.

        nArray = arrayNum

        It's my mistake. The two are the same

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved