How to reduce QT program start-up time when using

2019-08-04 02:59发布

问题:

My program relies on several DLLs during startup, including QtCore4.dll and QtGui4.dll from QT itself and ni488.dll from National Instruments. When I try using any of the functions in cbw32.dll (a 5 MB file found in the UniversalLibrary at http://www.mccdaq.com/software.aspx), my program suddenly takes 5+ seconds to start up, whereas previously it did so instantaneously. Is there anything I can do to reduce the time it takes to start up? For that matter, what is happening during that time, is the OS actively linking the functions, or merely trying to find the DLL? Is there any way to reduce the size of the DLL so as to include only the stuff that's relevant to my project? Or include that information in the executable itself (static linking, in other words)?

EDIT: loading the DLL in parallel is indeed a nice suggestion (and a technique that I'll use going forward), but doesn't get at what I perceive to be the core problem here. Having a 5 MB DLL take 5 seconds to load seems excessive, and to me indicates that there's a deeper problem. Are my expectations off here, and these load times are normal? Or is there really something wrong (and if so, what should I look into)?

回答1:

Why not load this dll dynamically in a parallel thread on start-up then?

HINSTANCE hGetProcIDDLL = LoadLibrary(L"library.dll");

Here is a nice example.



回答2:

I just ran into this exact problem myself. I'd been living with this 5+ second startup delay for quite a while, but on someone's suggestion, broke into the debugger during that pause. It appears that cbw32 is doing some lengthy initialization, probably in DllMain. I'd guess some hardware polling/resets/whatever going on during that time.

Someone suggested using /DELAYLOAD for cbw32.dll, which eliminates the lag, but I haven't tested functionality (yet) on a system with an applicable board...



标签: qt dll load-time