Instantiating C++ objects from QML has tremendous memory usage overhead

谁说我不能喝 提交于 2021-02-07 07:58:25

问题


Instantiating a QObject derived class on the heap in C++ gives me roughly about 160 bytes per object.

Registering the same object via qmlRegisterType() for creation from QML and creating the object dynamically via createObject() gives me a little over 2000 bytes per object.

That's quite the difference, almost 13 times more memory per object is being used when creating from QML. Note that the object doesn't have any bindings or anything extra compared to how it is in C++.

Naturally, being QObject derived means it is a non-visible object. So it shouldn't have any extra overhead as far as scene-graph rendering is concerned.

Note that I have ran tests with a significant amount of objects multiple times, getting consistent results and scaling up proportionally, so it is unlikely that it is due to some variance or QML engine memory pre-allocation.

Why is that happening? Is it normal? Is there a way to reduce it?

来源:https://stackoverflow.com/questions/41454010/instantiating-c-objects-from-qml-has-tremendous-memory-usage-overhead

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!