Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Why it works at Release, but in Debug, it can't run sucessfully
Forum Updated to NodeBB v4.3 + New Features

Why it works at Release, but in Debug, it can't run sucessfully

Scheduled Pinned Locked Moved Unsolved C++ Gurus
qml profiler
5 Posts 5 Posters 2.0k 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.
  • S Offline
    S Offline
    Solan
    wrote on 10 Jul 2017, 07:54 last edited by koahnig 7 Oct 2017, 08:25
    #1
    void Reconstruct::allocation()
    {
        //向系统申请分配指定size个字节的内存空间
        int tempSize = sizeof(double)*reparam.ParamsnX*reparam.ParamsnY*reparam.ParamsnZ;
        ImageOutSave = (double***)malloc(tempSize);
        //if (ImageOutSave == NULL) qDebug() << "ImageOutSave Null";
        for(unsigned int i = 0; i < reparam.ParamsnX; ++i)
        {
            int tempSizeX = sizeof(double)*reparam.ParamsnY*reparam.ParamsnZ;
            ImageOutSave[i] = (double**)malloc(tempSizeX);
            //if (ImageOutSave[i] == NULL) qDebug() << "ImageOutSave[" << i << "] Null";
            for(unsigned int j = 0; j < reparam.ParamsnY; ++j)
            {
                ImageOutSave[i][j] = (double*)malloc(sizeof(double)*reparam.ParamsnZ);
    
                for(unsigned int k = 0; k < reparam.ParamsnZ; ++k)
                    ImageOutSave[i][j][k]=0;
            }
        }
    }
    
    E J 2 Replies Last reply 10 Jul 2017, 08:14
    0
    • S Solan
      10 Jul 2017, 07:54
      void Reconstruct::allocation()
      {
          //向系统申请分配指定size个字节的内存空间
          int tempSize = sizeof(double)*reparam.ParamsnX*reparam.ParamsnY*reparam.ParamsnZ;
          ImageOutSave = (double***)malloc(tempSize);
          //if (ImageOutSave == NULL) qDebug() << "ImageOutSave Null";
          for(unsigned int i = 0; i < reparam.ParamsnX; ++i)
          {
              int tempSizeX = sizeof(double)*reparam.ParamsnY*reparam.ParamsnZ;
              ImageOutSave[i] = (double**)malloc(tempSizeX);
              //if (ImageOutSave[i] == NULL) qDebug() << "ImageOutSave[" << i << "] Null";
              for(unsigned int j = 0; j < reparam.ParamsnY; ++j)
              {
                  ImageOutSave[i][j] = (double*)malloc(sizeof(double)*reparam.ParamsnZ);
      
                  for(unsigned int k = 0; k < reparam.ParamsnZ; ++k)
                      ImageOutSave[i][j][k]=0;
              }
          }
      }
      
      E Offline
      E Offline
      Eeli K
      wrote on 10 Jul 2017, 08:14 last edited by
      #2

      @Solan If I wanted to be evil I would answer "because you write C, not C++". But if you want to get answers, you should give information about your system. At least Qt version, compiler name and version, hardware (processor).

      1 Reply Last reply
      1
      • S Solan
        10 Jul 2017, 07:54
        void Reconstruct::allocation()
        {
            //向系统申请分配指定size个字节的内存空间
            int tempSize = sizeof(double)*reparam.ParamsnX*reparam.ParamsnY*reparam.ParamsnZ;
            ImageOutSave = (double***)malloc(tempSize);
            //if (ImageOutSave == NULL) qDebug() << "ImageOutSave Null";
            for(unsigned int i = 0; i < reparam.ParamsnX; ++i)
            {
                int tempSizeX = sizeof(double)*reparam.ParamsnY*reparam.ParamsnZ;
                ImageOutSave[i] = (double**)malloc(tempSizeX);
                //if (ImageOutSave[i] == NULL) qDebug() << "ImageOutSave[" << i << "] Null";
                for(unsigned int j = 0; j < reparam.ParamsnY; ++j)
                {
                    ImageOutSave[i][j] = (double*)malloc(sizeof(double)*reparam.ParamsnZ);
        
                    for(unsigned int k = 0; k < reparam.ParamsnZ; ++k)
                        ImageOutSave[i][j][k]=0;
                }
            }
        }
        
        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 10 Jul 2017, 08:37 last edited by
        #3

        @Solan To add to @Eeli-K : why don't you say what is not working?
        Why do you use malloc and C style casts?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • V Offline
          V Offline
          VRonin
          wrote on 10 Jul 2017, 08:53 last edited by VRonin 7 Oct 2017, 08:55
          #4

          You are allocating WAY too much memory, just treat 1 dimension at a time, do not multiply the dimensions together from the start:

          double*** ImageOutSave=nullptr;
          ImageOutSave = new double**[reparam.ParamsnX];
           for(unsigned int i = 0; i < reparam.ParamsnX; ++i){
          ImageOutSave[i] = new double*[reparam.ParamsnY];
          for(unsigned int j = 0; j < reparam.ParamsnY; ++j)
                  {
          ImageOutSave[i][j] = new double [reparam.ParamsnZ];
          for(unsigned int k = 0; k < reparam.ParamsnZ; ++k)
                          ImageOutSave[i][j][k]=0;
          }
          }
          
          

          There are easier ways to manage this kind of containers though for example using boost multi array

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          2
          • A Offline
            A Offline
            Avtansh Sharma
            wrote on 12 Jul 2017, 10:38 last edited by
            #5

            @Solan
            It will not work in debug mode because in Debug mode there some extra initializations that happen behind the scenes. If you heavily use the pointers the visual debuggers won't help you out.
            For more information on this topic read about -Wall option in gcc for linux and go to msdn about debugger from microsoft windows.
            If the code you are writing from scratch then please use latest conventions of new and delete.

            1 Reply Last reply
            1

            1/5

            10 Jul 2017, 07:54

            • Login

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