📄 performance-qws.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Qt Toolkit - Qt/Embedded Performance Tuning</title><style type="text/css"><!--h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }a:link { color: #004faf; text-decoration: none }a:visited { color: #672967; text-decoration: none }body { background: white; color: black; }--></style></head><body bgcolor="#ffffff"><p><table width="100%"><tr><td><a href="index.html"><img width="100" height="100" src="qtlogo.png"alt="Home" border="0"><img width="100"height="100" src="face.png" alt="Home" border="0"></a><td valign="top"><div align="right"><img src="dochead.png" width="472" height="27"><br><a href="classes.html"><b>Classes</b></a>- <a href="annotated.html">Annotated</a>- <a href="hierarchy.html">Tree</a>- <a href="functions.html">Functions</a>- <a href="index.html">Home</a>- <a href="topicals.html"><b>Structure</b> <font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular" align="center" size=32>Qte</font></a></div></table><h1 align="center"> Qt/Embedded Performance Tuning</h1><br clear="all">When building embedded applications on low-powered devices, a numberof options are available that would not be considered in a desktopapplication environment. These options reduce the memory and/or CPUrequirements at the cost of other factors.<p><ul> <li><a href="features.html"><b>Tuning the functionality of Qt</b></a> <li><a href="#general">General programming style</a> <li><a href="#static">Static vs. Dynamic linking</a> <li><a href="#alloc">Alternative memory allocation</a></ul><p><a name="general"><h3>General programming style</h3></a><p>The following guidelines will improve CPU performance:<ul> <li>Create dialogs and widgets once, then QWidget::hide() and QWidget::show() them, rather than creating them and deleting them every time they are needed. This will use a little more memory, but will be much faster. Try to create them the first time "lazily" to avoid slow startup (only create the Find dialog the first time the user invokes it).</ul><p><a name="static"><h3>Static vs. Dynamic linking</h3></a><p>Much CPU and memory is used by the ELF linking process. You can makesignificant savings by using a static build of your application suite.This means that rather than having a dynamic library (<tt>libqte.so</tt>)and a collection of executables which link dynamically to that library,you build all the applications into a single executable and staticallylink that with a static library (<tt>libqt.a</tt>). This improves start-uptime, and reduces memory usage, at the expense of flexibility (to add a newapplication, you must recompile the single executable) and robustness (ifone application has a bug, it might harm other applications). If you needto install end-user applications, this may not be an option, but if you arebuilding a single application suite for a device with limited CPU powerand memory, this option could be very beneficial.<p>To compile Qt as a static library, add the <tt>-static</tt> options whenyou run configure.<p>To build your application suite as an all-in-one application, design eachapplication as a stand-alone widget or set of widgets, with only minimalcode in the <tt>main()</tt> function. Then, write an application that givessome way to choose among the applications (eg. a QIconView). The<a href="http://www.trolltech.com/products/qt/embedded/qpe.html">QPE</a>is an example of this - it can be built either as a set of dynamically-linkedexecutables, or as a single static application.<p>Note that you should generally still link dynamically against the standardC library and any other libraries which might be used by other applicationson your device.<p><a name=alloc><h3>Alternative memory allocation</h3></a><p>We have found that the libraries shipped with some C++ compilers onsome platforms have poor performance in the built-in "new" and "delete"operators. You might gain performance by re-implementing thesefunctions. For example, you can switch to the plain C allocatorsby adding the following to your code:<p><pre>void* operator new[](size_t size){ return malloc(size);}void* operator new(size_t size){ return malloc(size);}void operator delete[](void* p){ free(p);}void operator delete[](void* p, size_t size){ free(p);}void operator delete(void* p){ free(p);}void operator delete(void* p, size_t size){ free(p);}</pre><p><p><address><hr><div align="center"><table width="100%" cellspacing="0" border="0"><tr><td>Copyright
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -