April 12, 2012

aekam aekam
Ant Farmer
87 posts

[SOLVED] Memory operations in QList..

 

Hello,
In the QList<T>, if “append” or “insert” is called, internally “new” is performed to make room for new element.
My question is that will “delete” be performed when i call any of the “remove” function.??
or the memory will be deleted only upon call to destructor…

 Signature 

If you take care of inches, you won’t have to worry about miles… :)

5 replies

April 12, 2012

Andre Andre
Area 51 Engineer
6031 posts

There is not always a new performed; it depends on the data type you’re storing in QList. Do you have any issues with QList, or are you just curious?

Also: considder using QVector instead of QList. It is often a better choice.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

April 12, 2012

aekam aekam
Ant Farmer
87 posts

I am designing a code in which I need to store data of type structure.
Writing to and reading from QList will be frequent. So in order to prevent frequent “new” and “delete”, I need to know the operations behind the scene. in both cases, storing data to and removing data from QList or say in which scenarios new and delete will be performed.

 Signature 

If you take care of inches, you won’t have to worry about miles… :)

April 12, 2012

aekam aekam
Ant Farmer
87 posts

Note that the internal array only ever gets bigger over the life of the list. It never shrinks. The internal array is deallocated by the destructor and by the assignment operator, when one list is assigned to another.

I found this in help page of QList. As per this, memory is de-allocated only when the destructor is called or QList is assigned to it.

I consider this as solved.

 Signature 

If you take care of inches, you won’t have to worry about miles… :)

April 12, 2012

Andre Andre
Area 51 Engineer
6031 posts

Ok, good.
If you mark a topic as Solved, please do so by editing your opening post and prepending [Solved] to the title of the topic from there. There is an edit link on the right of each of your posts.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

April 12, 2012

aekam aekam
Ant Farmer
87 posts

Yes, i have already done it.
thanks… :)

 Signature 

If you take care of inches, you won’t have to worry about miles… :)

 
  ‹‹ QProgressDialog won’t block user inputs in MainWindow before it appears      How to write a additional code, which has to get triggered at the Scroll event of the QGraphicsView ››

You must log in to post a reply. Not a member yet? Register here!