Memory problem? [solved]

  • 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:

    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];


    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:

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

    How can I do the same for the bidimensional arrays?

    Thanks guys for your help!

  • Lifetime Qt Champion

    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

  • Hi there,

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


  • Lifetime Qt Champion

    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 :)

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

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

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

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


  • for allocating a 2-dimensional array on the heap have a look at

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

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

    thanks a lot guys!

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.