arraysqtmemory-managementqvectorqscopedpointer

QVector + QScopedPointer - Invalid parameter passed to C runtime function


I have a method, which generates a huge QVector<uchar> (SIZE: 354792000), and memmory is allocated/freed up dynamically, for convenience I use QScopedPointer:

void someMethod(int SIZE) {
  chVec.reset(new QVector<uchar>(SIZE));
       /*doing some stuff with an array...*/
  chVec.data()->clear();
  chVec.data()->squeeze();
}

Creating arrays of small size - no problem, you can also create one array of large size, but when I call the method again, I get the error "Invalid parameter passed to C runtime function". It went through a debugger, an error occurs when trying to allocate space for a new array:

template <typename T>
QVector<T>::QVector(int asize, const T &t)
{
    Q_ASSERT_X(asize >= 0, "QVector::QVector", "Size must be greater than or equal to 0.");
    if (asize > 0) {
        d = Data::allocate(asize);
        Q_CHECK_PTR(d); /*<------ Error occured*/
        d->size = asize;
        T* i = d->end();
        while (i != d->begin())
            new (--i) T(t);
    } else {
        d = Data::sharedNull();
    }
}

Data::allocate(asize); :

Q_REQUIRED_RESULT static QTypedArrayData *allocate(size_t capacity,
            AllocationOptions options = Default)
    {
        Q_STATIC_ASSERT(sizeof(QTypedArrayData) == sizeof(QArrayData));
        return static_cast<QTypedArrayData *>(QArrayData::allocate(sizeof(T),
                    Q_ALIGNOF(AlignmentDummy), capacity, options));
    }     

What could it be? A memory leak (it is impossible to allocate such a large chunk of contiguous memory again, since the previous call did not free the memory?)? ... I just can’t understand what the problem is, before leaving the method scope, I even manually clean the array and free the memory ... I would be grateful for any advice


Solution

  • The problem was solved by changing mingw32 to mingw64