Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Dynamic size matrix with QVarLengthArray



  • Hi i am making a software for stadistic calculus,
    then need to declare a matrix of given size
    it is declared only once time and dont resize during the process.

    Then need to create a matrix in the rangue of [1 to 10, 100 to 100.000] items.
    It only store doubles.

    In the begin process declare the matrix,populate with the numbers
    and make many calculus, not need to insert o delete items.
    Now i do:
    double matrix * = new double [dim1 * dim2];
    an when need the item (i,j) I do Aij = matrix[i*dim2+j];

    Then i have next-> FTH: (2336): *** Fault tolerant heap shim applied to current process. This is usually due to previous crashes. ***

    After reading some post, i see that matrix is stored in the heap.
    As can give me some problem.
    Question:

    1. Someone can tell me wich problems?

    Reading the doc i see that QVarLengthArray allocates the declared size of
    elements on the stack then grow up on the heap.
    If use QVarLengthArray, all elements will be in heap

    Question:
    2) QVarLengthArray will be a better choice o use std::vector with reserve() or which other?

    1. To avoid write on copy, how must to use QVarLengthArray,
      wit a pointer or with instance:

    QVarLengthArray * ptVLA;
    QVarLengthArray VLA;

    May be are basic question but i need high performance in my program
    Greetings


Log in to reply