📄 emb-performance.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><!-- /home/reggie/tmp/qt-3.0-reggie-5401/qt-x11-commercial-3.0.5/doc/qws.doc:485 --><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>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: #ffffff; color: black; }--></style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr bgcolor="#E5E5E5"><td valign=center> <a href="index.html"><font color="#004faf">Home</font></a> | <a href="classes.html"><font color="#004faf">All Classes</font></a> | <a href="mainclasses.html"><font color="#004faf">Main Classes</font></a> | <a href="annotated.html"><font color="#004faf">Annotated</font></a> | <a href="groups.html"><font color="#004faf">Grouped Classes</font></a> | <a href="functions.html"><font color="#004faf">Functions</font></a></td><td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>Qt/Embedded Performance Tuning</h1> 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="emb-features.html"><b>Tuning the functionality of Qt</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"></a><h2> General programming style</h2><a name="1"></a><p> The following guidelines will improve CPU performance:<ul><li> Create dialogs and widgets once, then <a href="qwidget.html#hide">QWidget::hide</a>() and<a href="qwidget.html#show">QWidget::show</a>() them, rather than creating them and deletingthem 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"></a><h2> Static vs. Dynamic linking</h2><a name="2"></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 main() function. Then, write an application that givessome way to switch between the applications (eg. a <a href="qiconview.html">QIconView</a>). 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 ofdynamically-linked executables, 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"></a><h2> Alternative memory allocation</h2><a name="3"></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> <!-- eof --><p><address><hr><div align=center><table width=100% cellspacing=0 border=0><tr><td>Copyright © 2002 <a href="http://www.trolltech.com">Trolltech</a><td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a><td align=right><div align=right>Qt version 3.0.5</div></table></div></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -