[Qt-interest] Replace Qt Allocator
Eric Clark
eclark at ara.com
Wed Sep 16 23:13:13 CEST 2009
> -----Original Message-----
> From: qt-interest-bounces at trolltech.com [mailto:qt-interest-
> bounces at trolltech.com] On Behalf Of David Walthall
> Sent: Wednesday, September 16, 2009 3:48 PM
> To: qt-interest at trolltech.com
> Subject: Re: [Qt-interest] Replace Qt Allocator
>
> Eric Clark wrote:
> > Our program uses a system allocator called nedmalloc. We override the
> > new and delete operators to use this system allocator. However, after
> > porting to Qt 4 we have ran into some issues with the QList class and
> > it's destructor. When the list is destructed, it attempts to free the
> > memory created by the list, but nedfree() crashes because the memory
> was
> > instantiated using the system allocator, malloc(). Here is the
> problem:
> >
> > The problem is indeed a violation of the ODR requirement in the ISO
> C++
> > spec. For example in this line:
> >
> > QModelIndexList indexes = list->selectionModel()->selectedRows();
> >
> > QModelIndexList exists in the local binary due to being a templated
> type
> > based on QList, therefore its destructor is called from the local
> binary
> > where ::operator delete has been defined to invoke nedmalloc.
> > Unfortunately the initial constructor of the list (selectedRows())
> > exists in one of the Qt DLL binaries where ::operator new is defined
> to
> > invoke the system allocator. Therefore the list is being constructed
> > with the system allocator and destructed with nedmalloc - this
> obviously
> > enough provokes a segfault as ODR is violated.
>
> Did you take Thiago's advice and recompile Qt to use nedmalloc?
>
> http://lists.trolltech.com/pipermail/qt-interest/2009-June/009114.html
Yes. I pointed out in the current thread that I can get it to work by compiling nedmalloc into Qt, but that there is more than just changing the source of qFree(), qMalloc() and qRealloc() to call nedfree(), nedmalloc() and nedrealloc() respectively. I also have to add a global new and delete implementation to qglobal.h that invokes qMalloc() and qFree(). Then everything works.
The main reason for this post was to understand why Qt offers the ability to "drop-in" a system allocator by changing the source of qFree(), qMalloc() and qRealloc(), if it is not the only thing that needs to be done? I also have to add the global new and delete as mentioned before. This could be easily fixed if Qt had already overridden those operators to invoke the qFree() and qMalloc() that exist in Qt. Then I would have only had to swap out the source of those functions, build QtCore and everything would work just fine.
>
>
> David
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list