Qt and custom memory management
-
I have been researching this topic online and have been given the impression that it would not be easy and/or effective to incorporate custom memory management in a Qt application. This post is particularly alarming: https://stackoverflow.com/questions/25931668/does-qt-allready-have-its-own-new-and-delete-operators; though I am not sure how true its statements are (regarding PIMPL).
Since the application I am building is complex, modular, and both memory, processor, and potentially gpu intensive, I really need to do my own memory management. I am currently leaning towards writing my own custom shared and smart pointers to do much of the memory management (especially for third party libraries) and it would help to get the facts straight. Is custom memory management possible and/or practical with Qt? Can I do this without rewriting the Qt code? If I did need to rewrite it, is there a particular set of base classes that would cover a large portion or would I need to effectively rewrite everything?
-
@primem0ver said in Qt and custom memory management:
Is custom memory management possible and/or practical with Qt?
Depends on what you mean by "custom memory management". If it means your own heap manager, then for sure it isn't practical.
Can I do this without rewriting the Qt code?
Not to any tangible result. With few exceptions Qt classes will
new
their own private data to keep binary compatibility. Thus even you write you own heap manager (which I really doubt the wisdom of) you're not going to get more than optimizedvoid *
allocation.If I did need to rewrite it, is there a particular set of base classes that would cover a large portion or would I need to effectively rewrite everything?
Not sure, but it isn't trivial. The private classes inherit one another,
QSharedData
andQObject
are starting points for investigation. -
@kshegunov
Thanks for the input. I am really curious why you feel I shouldn't write my own heap manager. -
@primem0ver said in Qt and custom memory management:
Thanks for the input. I am really curious why you feel I shouldn't write my own heap manager.
that isn't what he said. he said it wouldn't work well with the Qt framework. You can write whatever memory manager you like. simply override the default clib memory management functions and you can custom handle any memory the OS is willing to give you. however, if the framework is making certain "assumptions" about the state and capabilities of the heap then you WILL break something.
-
If I was interested in testing my own build of Qt with my heap manager, how would I go about creating a custom build and setting my projects to use that build in Visual Studio using the plugin? Any pointers on where to get information on how to do this? I tried looking it up but could only find info on doing it with Qt Creator.