Does QStringList store data on stack or on heap?

300 Views Asked by At

In the code below:

void fun()
{
    QString aa("aa");
    QString bb("bb");
    QStringList a;
    a<<aa;
    a<<bb;
}

I know QString stores its data on heap, but how about QStringList? Does it allocate an array on stack, or on heap and only store the pointer to the array on stack?

1

There are 1 best solutions below

4
On BEST ANSWER

QList technically is:

class QList
{
    QListData::Data* p;
};

where QListData::Data is:

struct Data 
{
    QtPrivate::RefCount ref;
    int alloc, begin, end;
    void *array[1];
};

So QList itself allocates memory on the heap and stores a pointer to it.