Big latency when calling standard C++ code from Qt
-
Hello,
I'm writing an app for Maemo, using a library in standard C++ and Qt for GUI. I have a problem when calling a std::C++ function from My Qt code: I takes almost 3 second only to enter the function.
Here is my code when calling the function (with timer):
https://gitorious.org/mverbiste/mverbiste/blobs/24c4175dd69b2b8e87506247a34d4e765d86bb31/mainwindow.cpp#line181
!http://i.imgur.com/u2wiS.png(Caller)!And inside getConjugation(), with timer:
!http://i.imgur.com/J0rRl.png(Callee)!Here is the result with the time recorded, running on Maemo phone:
!http://i.imgur.com/Ruo50.png(Time measured)!Can you help me point out the cause of problem? Can it be fixed?
-
I am somewhat surprised by this, and I have not many ideas, but first one question: Is that code in some external dynamic library, or is part of your executable? I have zero knowledge about linkers, and that kind of things, but I think that Maemo/MeeGo had some kind of "booster" that started applications from a preloaded executable that links against Qt in order to improve startup time, because dynamic linking is somewhat slow on Linux. Something like KDE's kdeinit. Maybe is something worth investigating.
-
The code is not in external dynamic library. It is part of my executables.
-
I wonder if the freVerbDic variable is forced to initialize again when passed to called function (I have little experience in C++)?
-
I'm no C++ expert at all, but I understand that since you are passing a constant reference, there is no change at all.
Can you do a test changing the reference with a pointer, and see if changes anything?
Also, maybe something Maemo specific is happening, but maybe is not and maybe this question is more suited to the C++ forum (that's why I hate forums, all this fragmentation). Can you test the code on a normal computer (if is crossplatform) or in an emulator to see if it makes a difference?
-
Thanks
I tried on normal computer (via "Simulator" on QtSDK), it is OK (fast).
In the code above, the "freVerbDic" variable is defined as:
@FrenchVerbDictionary *freVerDict@
So, how to pass as pointer? -
Perhaps its a revenge for using camel case naming convention for non-Qt C++ identifier names, eh eh.
-
[quote author="hongquan" date="1352480105"]Thanks
I tried on normal computer (via "Simulator" on QtSDK), it is OK (fast).
In the code above, the "freVerbDic" variable is defined as:
@FrenchVerbDictionary *freVerDict@
So, how to pass as pointer?[/quote]In getConjugation declaration, you have to say that is a pointer, that is, use something like: "FrenchVerbDictionary* fvd". Then, were the function is invoked, use "&freVerbDic".
IF you are new with C/C++, search "pass by pointer" or "pass by reference".
-
[quote author="disperso" date="1352815647"]
In getConjugation declaration, you have to say that is a pointer, that is, use something like: "FrenchVerbDictionary* fvd". Then, were the function is invoked, use "&freVerbDic".IF you are new with C/C++, search "pass by pointer" or "pass by reference".[/quote]
Wonderful! I solved this.
I changed to pass argument like this
@getConjugation(*freVerbDic,...@
Thanks disperso.
My old code made freVerbDic to re-initialize. I confirmed this by checking its properties outside and inside getConjugation() function.@matti I don't know about the naming convention. Could you let me know?
I'm a Python & C guy, just begin with C++. -
Ah, great. Nice that you fixed it because I wasn't really sure what else could it be!
Since you say that know C, just note that normally you can use pointers in C++ the same way you are used to. References are very similar.
In some places of Qt (or just in C++, like with the "this" keyword) pointers are used instead of references, so is not a big deal (in my opinion). But learn how to use them, since they are useful, too.
About matti: he was probably joking. Normally Qt uses "CamelCase", and I don't see why you should not use it. An interesting article that mentions a little bit about this things: http://doc.qt.digia.com/qq/qq13-apis.html