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. Memory problem? [solved]
Forum Updated to NodeBB v4.3 + New Features

Memory problem? [solved]

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 2.6k Views 1 Watching
  • 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
    scamiolo
    wrote on last edited by
    #1

    Hi guys
    I hope someone can help me with the following issue. I created a project with Qt creator which builds perfectly but after launching the program unexpectely quits with a segmentation fault. I guess this is a problem related with memory. I use very large array of maps in the following variable:

    [code]
    map <char,int> conserved1_f[50000];
    map <char,int> notConserved1_f[50000];
    map <char,int> conserved2_f[50000];
    map <char,int> notConserved2_f[50000];
    map <string,int> codons;
    map <string,int> conservedCodons1[50000][18];
    map <string,int> notConservedCodons1[50000][18];
    map <string,int> conservedCodons2[50000][18];
    map <string,int> notConservedCodons2[50000][18];

    [/code]

    If I try to reduce the dimensions of those arrays I get the program regularly launched and perfectly working. It is quite strange since the program worked smoothly before implementing the GUI in Qt.
    Do you have any idea on what could be the problem?
    If it is a memory problem I could use the "new" statement. I did this before for very large arrays.
    The first variable could be declared like:

    [code]
    map<char,int> *conservedFavorite = new map<char,int>[5000000];
    [/code]

    How can I do the same for the bidimensional arrays?

    Thanks guys for your help!

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

      Hi and welcome to devnet,

      You are creating big arrays on the stack, which is also used by the other libraries you are using (including Qt) and it size is limited. Since you're using quiet a lot of memory with your data, you should allocate them on the heap, or even better, use Qt's container classes.

      Have a look at QMap and QVector, you can combine them to have your two dimensional maps.

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • S Offline
        S Offline
        scamiolo
        wrote on last edited by
        #3

        Hi there,

        thanks a lot. You advice helped me a lot. I go for it straight away!

        thanks!

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You're welcome !

          If this solves your problem, please update the thread's title prepending [solved] so other forum users may know a solution has been found :)

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • S Offline
            S Offline
            scamiolo
            wrote on last edited by
            #5

            I am trying to declare map in the heap memory. It looks like it is working well with one dimension array:

            [code]
            map<char,int> *conservedFavorite = new map<char,int>[5000000];
            [/code]

            How am I supposed to do the same with the bidimensional one like

            [code]
            map <string,int> conservedCodons1[50000][18];
            [/code]

            thanks

            1 Reply Last reply
            0
            • M Offline
              M Offline
              Mario84
              wrote on last edited by
              #6

              for allocating a 2-dimensional array on the heap have a look at http://stackoverflow.com/questions/936687/how-do-i-declare-a-2d-array-in-c-using-new

              but as SGaist already said, it is better to use Qt's container classes...

              1 Reply Last reply
              0
              • S Offline
                S Offline
                scamiolo
                wrote on last edited by
                #7

                I used QMap as suggested and everything went smooth and nice!

                thanks a lot guys!

                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