[Qt-interest] QList: Force a deep copy?
Samuel Rødal
sroedal at trolltech.com
Wed Jul 1 10:08:26 CEST 2009
Eric Clark wrote:
> I can understand the reason for "hiding" detach from QList's documentation due to the fact that it is not usually necessary. However, in contrast to that, there are functions in the documentation, i.e. QWidget::setParent, that are documented, but it is stated that "It is very unlikely that you will ever need this function." I see the detach function as being very similar to the QWidget::setParent function in the sense that you will probably never need to use it; however, it should be documented. There may be cases when it needs to be used.
>
> In reply to Diego's question, I would not consider your question to be naïve, it is actually a good question. I have a bug in my application with the QList class that I cannot seem to figure out, and trying to produce a deep copy of the list was a test to try to fix my bug. However, I will point out that the deep copy did not fix my bug.
>
> Basically, I am making a call to QItemSelectionModel::selectedIndexes as so:
>
> void Foo()
> {
> QModelIndexList list = mySelectionItem->selectedIndexes();
> ...
> }
>
> There is more code in this function, but it crashes even if it is just the one line I have given. My application crashes when it exits the function, and it crashes in QList's destructor. My application replaces the global new and delete operators with nedmalloc instead of the default malloc. We have been doing this for quite some time and have never ran into an issue with anything in Qt, until this. For some reason nedmalloc is stating that some memory is trying to be freed more than once. I do not know why this is happening, but I do know that if I change the allocator back to malloc, everything works fine. However, this is not the ideal solution. We have tested the performance of nedmalloc against malloc and nedmalloc produces much faster results. On the order of about a 200% increase in speed. That is a BIG difference! We need to be able to use nedmalloc in our application because speed is of great importance to us. The only way I can get this function to not crash is to
do this:
>
> void Foo()
> {
> QModelIndexList *list = new QModelIndexList(mySelectionItem->selectedIndexes());
> ...
> }
>
> ...and never delete the list. This works only because I don't delete the list. However, that is not a solution since it can be very costly having this type of "forced" memory leak. I thought that if I tried to do a deep copy instead, it might fix the problem, but it did not.
>
> Any help with this issue would be greatly appreciated. Especially if anyone has attempted to use nedmalloc in their Qt application.
>
> Thanks,
> Eric
Sounds to me like the QList destructor is getting inlined, so that
nedmalloc is used to free something that was allocated inside Qt with a
regular malloc.
Would it be possible for you to compile Qt as well with nedmalloc enabled?
--
Samuel
More information about the Qt-interest-old
mailing list