﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-RTY 实践出真知-随笔分类-转载随笔</title><link>http://www.cppblog.com/lauer3912/category/16818.html</link><description>没有理由不学习</description><language>zh-cn</language><lastBuildDate>Sat, 19 Jul 2014 15:01:57 GMT</lastBuildDate><pubDate>Sat, 19 Jul 2014 15:01:57 GMT</pubDate><ttl>60</ttl><item><title>webkit webApp 开发技术要点总结,涉及ViewPort，离线浏览，缩放，事件，屏幕旋转，防止滚动条出现，双手滑动，判断设备，拼写修正，CSS等(转载)</title><link>http://www.cppblog.com/lauer3912/archive/2013/03/13/198388.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Wed, 13 Mar 2013 09:12:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2013/03/13/198388.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/198388.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2013/03/13/198388.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/198388.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/198388.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 原文：http://www.cnblogs.com/pifoo/archive/2011/05/28/webkit-webapp.htmlwebkit webApp 开发技术要点总结如果你是一名前端er,又想在移动设备上开发出自己的应用，那怎么实现呢？幸好，webkit内核的浏览器能帮助我们完成这一切。接触 webkit webApp的开发已经有一段时间了，现把一些技巧分享给大家 ：1. view...&nbsp;&nbsp;<a href='http://www.cppblog.com/lauer3912/archive/2013/03/13/198388.html'>阅读全文</a><img src ="http://www.cppblog.com/lauer3912/aggbug/198388.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2013-03-13 17:12 <a href="http://www.cppblog.com/lauer3912/archive/2013/03/13/198388.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>为你的Cocoa应用程序加入更新支持：Sparkle 简介</title><link>http://www.cppblog.com/lauer3912/archive/2013/02/07/197767.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Thu, 07 Feb 2013 06:14:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2013/02/07/197767.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/197767.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2013/02/07/197767.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/197767.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/197767.html</trackback:ping><description><![CDATA[<h2 class="arcd-ttl">为你的Cocoa应用程序加入更新支持：Sparkle 简介</h2>
                    <p class="arcd-info"><span>发布于：2010-09-20 13:06</span><span>阅读数：3141</span></p>
                    <div class="arcd-sum">
                    	<p class="p1">作为一名桌面软件开发者，应该提早考虑程序的更新问题。如何将程序更新及时优雅的推送给用户，是维持用户忠诚度和提高软件使用体验的一个重要方面。而作为Cocoa应用程序开发者，</p>
                        
                        <span class="pun pun1">&#8220;</span><span class="pun pun2">&#8221;</span>
                    </div>
                
            	
            
            	
            		<div class="tags">
                    	
                    	
                    	<a id="read" class="font f3">阅读器</a>
                        
                    	
                    </div>
                    
                    
                    	
                    		<div id="article"><p>转自 ibuick.com，原文&nbsp; <a target="_blank" href="http://ibuick.com/index.php/archives/add-automatic-update-support-over-cocoa-app-via-sparkle-framework">http://ibuick.com/index.php/archives/add-automatic-update-support-over-cocoa-app-via-sparkle-framework</a></p>
<hr />
<p>作为一名桌面软件开发者，应该提早考虑程序的更新问题。如何将程序更新及时优雅的推送给用户，是维持用户忠诚度和提高软件使用体验的一个重要方面。而作为Cocoa应用程序开发者，我们可以选择自己手动来实现此功能，也可以选择一些优秀的开源框架。<span style="text-decoration: underline;"><a href="http://sparkle.andymatuschak.org/">Sparkle</a></span>就是其中之一。</p>
<p><span style="text-decoration: underline;"><a href="http://sparkle.andymatuschak.org/">Sparkle</a></span>是一个非常简单且易用的Cocoa应用程序更新框架。本篇文章将使用一个简单的例子，教你如何使用<span style="text-decoration: underline;"><a href="http://sparkle.andymatuschak.org/">Sparkle</a></span>为你的Cocoa应用程序加入更新支持。</p>
<p>1: 新建一个Cocoa Application，TestSparkle</p>
<p><img src="http://www.cocoachina.com/cms/uploads/allimg/100920/1321401G5-0.png" alt="wpid-wpid-xcodecocoaapplication-2010-09-10-16-11-2010-09-10-16-11.png" height="415" width="544" /></p>
<p>&nbsp;</p>
<p><img src="http://www.cocoachina.com/cms/uploads/allimg/100920/13214063Z-1.png" alt="wpid-wpid-cocoaapplicationwithsparkle-2010-09-10-16-11-2010-09-10-16-11.png" height="392" width="541" /><br />
2: 去到<span style="text-decoration: underline;"><a href="http://sparkle.andymatuschak.org/">Sparkle</a></span>下载<span style="text-decoration: underline;"><a href="http://sparkle.andymatuschak.org/files/Sparkle%201.5b6.zip">Sparkle Framework</a></span>，最新版本为 1.5b6,</p>
<p><img src="http://www.cocoachina.com/cms/uploads/allimg/100920/13214060c-2.png" alt="wpid-wpid-sparkle-2010-09-10-16-11-2010-09-10-16-11.png" height="340" width="545" /><br />
Sparkle Test App.app 是一个用来演示<span style="text-decoration: underline;"><a href="http://sparkle.andymatuschak.org/">Sparkle</a></span>更新框架的一个应用程序。</p>
<p>Extras文件夹下提供了<span style="text-decoration: underline;"><a href="http://sparkle.andymatuschak.org/">Sparkle</a></span>的标准图标，Release Notes模版，软件签名工具，源代码和Appcast.xml示例文件，我们后面会再讲到这些工具和文件。</p>
<p>With Garbage Collection, 是一个加入了Garbage Collection支持的<span style="text-decoration: underline;"><a href="http://sparkle.andymatuschak.org/">Sparkle</a></span>分发版，如果你的应用程序运行在有GC的环境下，则可以使用这个版本的<span style="text-decoration: underline;"><a href="http://sparkle.andymatuschak.org/">Sparkle</a></span></p>
<p>Sparkle.framework 是通用分发版，笔者建议大家使用此版本的<span style="text-decoration: underline;"><a href="http://sparkle.andymatuschak.org/">Sparkle</a></span>。</p>
<p>3: 链接<span style="text-decoration: underline;"><a href="http://sparkle.andymatuschak.org/">Sparkle</a></span>框架到TestSparkle工程</p>
<p>拖拽Sparkle.framework(或 with Garbage Collection下的  
Sparkle.framework)到TestSparkle的Linked Frameworks下，在弹出窗口中记得选中&#8221;Copy items 
 into destination group&#8217;s folder (if needed)&#8221;前面的复选框。</p>
<p><img src="http://www.cocoachina.com/cms/uploads/allimg/100920/13214014c-3.png" alt="wpid-wpid-addsparkletotestsparkle-2010-09-10-16-11-2010-09-10-16-11.png" height="328" width="542" /></p>
<p>4: 为你的工程新建一个Copy Files Build Phase,</p>
<p><img src="http://www.cocoachina.com/cms/uploads/allimg/100920/1321402103-4.png" alt="wpid-wpid-addcopyfilesbuildphase-2010-09-10-16-11-2010-09-10-16-11.png" height="328" width="543" /><br />
5: 右键点击这个新建的Copy Files Build Phase，并在弹出窗口中，点击Destination下拉框，选择Frameworks</p>
<p><img src="http://www.cocoachina.com/cms/uploads/allimg/100920/1321403625-5.png" alt="wpid-wpid-copyfilesbuildphaseforframework-2010-09-10-16-11-2010-09-10-16-11.png" height="386" width="542" /><br />
6: 将Linked Framworks下的Sparkle.framework拖拽到这个新建的Copy Files Build Phase 中</p>
<p><img src="http://www.cocoachina.com/cms/uploads/allimg/100920/13214033D-6.png" alt="wpid-wpid-addsparkle-2010-09-10-16-11-2010-09-10-16-11.png" height="328" width="543" /><br />
7: 在Interface Builder中打开TestSparkle的MainMenu.xib(nib), 然后点击Interface Builder&#8211;&gt;Files&#8211;&gt;Read Class Files</p>
<p><img src="http://www.cocoachina.com/cms/uploads/allimg/100920/1321403500-7.png" alt="wpid-wpid-readclassfiles-2010-09-10-16-11-2010-09-10-16-11.png" height="284" width="290" /></p>
<p>8: 将Sparkle.framework中的所有头文件选中并读取</p>
<p><img src="http://www.cocoachina.com/cms/uploads/allimg/100920/132140M22-8.png" alt="wpid-wpid-readheaderfiles-2010-09-10-16-11-2010-09-10-16-11.png" height="363" width="543" /><br />
9: 从Library中拖拽一个 NSObject到MainMenu主窗口.</p>
<p><img src="http://www.cocoachina.com/cms/uploads/allimg/100920/1321406246-9.png" alt="wpid-wpid-addobject-2010-09-10-16-11-2010-09-10-16-11.png" height="363" width="543" /></p>
<p>10: 点击此Object对象，点击Inspector，设定此Object的Class为 SUUpdater</p>
<p><img src="http://www.cocoachina.com/cms/uploads/allimg/100920/1321405R0-10.png" alt="wpid-wpid-SUUpdater-2010-09-10-16-11-2010-09-10-16-11.png" height="355" width="301" /></p>
<p>11: 添加一个菜单项到到TestSparkle Menu，重命名为 Check For Updates&#8230;</p>
<p><img src="http://www.cocoachina.com/cms/uploads/allimg/100920/13214024X-11.png" alt="wpid-wpid-Checkupdatesmenuitem-2010-09-10-16-11-2010-09-10-16-11.png" height="322" width="543" /></p>
<p>12: 将 Check for Updates&#8230;菜单项的Send Actions指向Updater Object的checkForUpdates方法</p>
<p><img src="http://www.cocoachina.com/cms/uploads/allimg/100920/13214044c-12.png" alt="wpid-wpid-addactionforupdate-2010-09-10-16-11-2010-09-10-16-11.png" height="353" width="542" /><br />
13: 保存Interface Builder的所有更改，退出Interface Builder。</p>
<p>14: 为了安全防止应用程序更新遭到恶意篡改，我推荐对应用程序更新添加数字签名。</p>
<p>Sparkle使用DAS SHA-1 来对程序更新包进行数字签名。</p>
<p>打开终端，进入步骤2中存放已下载的Sparkle包的文件夹，进入Extras&#8211;&gt;Signing Tools，</p>
<p>执行,</p>
<div class="codecolorer-container bash default" style="overflow: auto; white-space: nowrap; width: 435px;">
<div class="bash codecolorer">ruby generate_keys.rb</div>
</div>
<p>这个命令将会生成两个文件 dsa_priv.pem 和 dsa_pub.pem，也就是私钥和公钥，请妥善保存这两个文件，如果私钥丢失，你得用户将再也无法自动通过已安装的程序来获得更新的更新。</p>
<p>15: 建立一个 App Cast Feed文件</p>
<p>Sparkle的运作机理其实非常简洁，本地应用程序Info.plist中含有一个URL，此URL指向一个在你网站上的App Cast  
Feed XML文件。当你发布更新的时候，上传新的app到你的网站，更新此app cast xml  
feed。这样，客户端程序在运行检查更新时，会根据Info  
Plist中的URL找到并Parse此文件，跟本地软件版本进行比对。如果发现更新，则提示用户。这就是App Cast XML  
Feed文件的作用。</p>
<p>在步骤14中提到的Extras文件夹下，有一个App Cast XML Feed文件的模版：</p>
<p>&nbsp;</p>
<p>http://you.com/app/2.0.html<br />
<br />
Wed, 09 Jan 2006 19:20:11 +0000<br />
<br />
http://you.com/app/1.5.html<br />
<br />
Wed, 01 Jan 2006 12:20:11 +0000<br />
<span class="sc-1">&lt;!-- Now here's an example of a version with a  
weird internal version number (like an SVN revision) but a  
human-readable external one. --&gt;</span><br />
http://you.com/app/1.4.html<br />
<br />
Wed, 25 Dec 2005 12:20:11 +0000</p>
<p>我们可以看出，这其实是一个标准的RSS Feed格式的XML文件。我们只要修改相应的项目即可。</p>
<p>下面我们就来一步步的演示如何使用Sparkle为你的程序加入更新支持。</p>
<p>16: 我们首先在本地搭建一个可用于测试软件更新的网站。打开Mac OS X系统偏好设置(System Preferences),  
找到共享(Sharing)，开启Web共享(Web  
Sharing)，并通过点击图中所示URL测试Web共享是否成功开启。http://10.0.1.2/~buick <span style="color: #ff0000;">你的显示可能与此不同，，，，</span></p>
<p><img src="http://www.cocoachina.com/cms/uploads/allimg/100920/1321402048-13.png" alt="wpid-wpid-websharing-2010-09-10-16-11-2010-09-10-16-11.png" height="454" width="542" /><br />
17: 打开你的XCode中 TestSparkle 工程，编辑 TestSparkle-Info.plist，加入两个属性，SUPublicDSAKeyFile 和 SUFeedURL</p>
<p><img src="http://www.cocoachina.com/cms/uploads/allimg/100920/1321401K7-14.png" alt="wpid-wpid-info.plist-2010-09-10-16-11-2010-09-10-16-11.png" height="412" width="543" /></p>
<p>其中，SUFeedURL 将是指向一个 App Cast XML Fee 的 URL，比如我的测试地址是 <span style="text-decoration: underline;"><a href="http://10.0.1.2/%7Ebuick/testsparkleappcast.xml">http://10.0.1.2/~buick/testsparkleappcast.xml</a></span>
  ，SUPublicDSAKeyFile 指向公钥，我们把刚才步骤14中生成的 dsa_pub.pem 加入到工程的Resources中，并在
  TestSparkle-Info.plist 中指定此公钥的名称，，，，那么现在的TestSparkle-Info.plist应该是这样</p>
<p><a rel="attachment wp-att-1106" href="http://ibuick.com/index.php/archives/add-automatic-update-support-over-cocoa-app-via-sparkle-framework/wpid-wpid-configuration-2010-09-10-16-11-2010-09-10-16-111-2"><img class="alignnone size-full wp-image-1106" title="wpid-wpid-configuration-2010-09-10-16-11-2010-09-10-16-111" src="http://www.cocoachina.com/cms/uploads/allimg/100920/132140D41-15.png" alt="" height="412" width="543" /></a></p>
<p>整个配置完成，我们现在来构建一个TestSparkle.app的1.0版本，点击Build and Run</p>
<p><img src="http://www.cocoachina.com/cms/uploads/allimg/100920/1321401T0-16.png" alt="wpid-wpid-TestSparkle-2010-09-10-16-11-2010-09-10-16-11.png" height="323" width="542" /><br />
启动TestSparkle.app, 在TestSparkle菜单下，确认Check for Updates&#8230;按钮处于可用状态，如果是灰色不可点击，则返回Interface Builder修改。</p>
<p><img src="http://www.cocoachina.com/cms/uploads/allimg/100920/13214025G-17.png" alt="wpid-wpid-checkforupdates-2010-09-10-16-11-2010-09-10-16-11.png" height="242" width="227" /></p>
<p>将此 TestSparkle.app 1.0 版本拷贝到别处备用。然后返回XCode，将应用程序版本改为1.1,然后构建工程。将TestSparkle.app 的1.1版本打包成zip文件，改名为TestSparkle_1.1.zip</p>
<p>将 dsa_priv.pem (私钥) 和 TestSparkle_1.1.zip 拷贝到 Extras下的Signing Tool文件夹中，</p>
<p><img src="http://www.cocoachina.com/cms/uploads/allimg/100920/132140B34-18.png" alt="wpid-wpid-signing-2010-09-10-16-11-2010-09-10-16-11.png" height="298" width="542" /></p>
<p>打开终端进入到此文件夹，执行：</p>
<div class="codecolorer-container bash default" style="overflow: auto; white-space: nowrap; width: 435px;">
<div class="bash codecolorer">ruby sign_update.rb TestSparkle_1.1.zip dsa_priv.pem</div>
</div>
<p><img src="http://www.cocoachina.com/cms/uploads/allimg/100920/1321401011-19.png" alt="wpid-wpid-sign-2010-09-10-16-11-2010-09-10-16-11.png" height="323" width="542" /><br />
便可得到升级包的签名，MCwCFDZsrVGB+PewvxioJcvptkqchXi3AhQOZDJ4UukRM2/bYmZzzbHTxM2kpA==</p>
<p>用文本编辑器创建一个xml文件(UTF-8 编码)，内容如下：</p>
<p>http://10.0.1.2/~buick &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;The latest TestSparkle updates from localhost, more hot features and sweeties<br />
en</p>
<p>Fri, 10 Sept 2010 0:00:00 +0300 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; http://10.0.1.2/~buick</p>
<p><span style="color: #ff0000;">注意(由于本网站HTML的设置问题，如果你直接拷贝以上XML Feed文件到你本地测试可能会出编码问题导致XML Parse失败，请到本文最后下载此文件，以及工程压缩包)。</span></p>
<p>把此XML另存为 testsparkleappcast.xml</p>
<p>熟悉RSS Feed的读者可能很容易理解此文件，，如果我们在浏览器中直接访问此URL，我们会看到</p>
<p><img src="http://www.cocoachina.com/cms/uploads/allimg/100920/1321401950-20.png" alt="wpid-wpid-feed-2010-09-10-16-11-2010-09-10-16-11.png" height="380" width="543" /></p>
<p>而我们要关注的只是这两段:</p>
<p>这段指定的URL是一个介绍页面，如果你希望在更新提示窗口中出现一个介绍新版本的页面(或者说release notes)，则使用此URL定向到你网站上的新版本介绍页面。</p>
<p>Sparkle非常贴心的为大家提供了一个模版，在Extras/Release Notes Templates 文件夹下可找到</p>
<p>enclosure sparkle:version=&#8220;1.1&#8221;  
sparkle:dsaSignature=&#8220;MCwCFDZsrVGB+PewvxioJcvptkqchXi3AhQOZDJ4UukRM2/bYmZzzbHTxM2kpA==&#8220;
  url=&#8220;http://10.0.1.2/~buick/TestSparkle_1.1.zip&#8221; length=&#8220;436264&#8221;  
type=&#8220;application/octet-stream&#8221;/&gt;</p>
<p>这段是实现Sparkle Update的关键，</p>
<p>sparkle:version=&#8220;1.1&#8221; 是指当前更新包版本号，客户端程序就是根据这个版本号来和本地APP进行比对，如果发现不同则提示更新。</p>
<p>sparkle:dsaSignature=&#8220;MCwCFDZsrVGB+PewvxioJcvptkqchXi3AhQOZDJ4UukRM2/bYmZzzbHTxM2kpA==&#8220; 这个就是我们刚才为更新包生成的数字签名</p>
<p>url=&#8220;<span style="text-decoration: underline;"><a href="http://10.0.1.2/%7Ebuick/TestSparkle_1.1.zip">http://10.0.1.2/~buick/TestSparkle_1.1.zip</a></span>&#8221; 指向更新包下载地址</p>
<p>length=&#8220;436264&#8221; 指更新包的大小，上传上去前用 终端 ls -al 命令可查看</p>
<p>type=&#8220;application/octet-stream&#8221; 是一个想对固定的值，一般不用修改。</p>
<p>现在把testsparkleappcast.xml 和 TestSparkle_1.1.zip 拷贝到</p>
<p>你的用户主目录/Sites 下 (~/Sites,具体路径依你个人配置而定)</p>
<p><img src="http://www.cocoachina.com/cms/uploads/allimg/100920/1321401350-21.png" alt="wpid-wpid-path-2010-09-10-16-11-2010-09-10-16-11.png" height="352" width="543" /><br />
然后在浏览器敲入 <span style="text-decoration: underline;"><a href="http://10.0.1.2/%7Ebuick/testsparkleappcast.xml">http://10.0.1.2/~buick/testsparkleappcast.xml</a></span></p>
<p>如果能够看到类似网页，，，说明一切正常。</p>
<p>下面找到我们刚才保存的TestSparkle.app 1.0版本，运行并点击 Check for Updates&#8230; 如果一切正常，你可以看到</p>
<p><img src="http://www.cocoachina.com/cms/uploads/allimg/100920/1321401116-22.png" alt="wpid-update1-2010-09-10-16-11.png" height="383" width="543" /></p>
<p>点击Install Update，如果更新成功，即可显示：</p>
<p><img src="http://www.cocoachina.com/cms/uploads/allimg/100920/132140DG-23.png" alt="wpid-complee-2010-09-10-16-11.png" height="209" width="464" /></p>
<p>然后再次点击Check for Updates, 你会看到</p>
<p><img src="http://www.cocoachina.com/cms/uploads/allimg/100920/1321406312-24.png" alt="wpid-latest-2010-09-10-16-11.png" height="217" width="467" /></p>
<p>最后希望你与Sparkle合作愉快。</p>
<p><span style="text-decoration: underline;"><a href="https://files.me.com/buickwang555/rq9k37">点击此处下载本次工程源代码和示例XML Feed文件，另外，安装包里面还带有一个Sparkle的简体中文包，将它放入你的Sparkle.framework/Resources下即可。</a></span></p></div><img src ="http://www.cppblog.com/lauer3912/aggbug/197767.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2013-02-07 14:14 <a href="http://www.cppblog.com/lauer3912/archive/2013/02/07/197767.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>IOS - 文字色彩</title><link>http://www.cppblog.com/lauer3912/archive/2013/02/05/197743.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Tue, 05 Feb 2013 07:24:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2013/02/05/197743.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/197743.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2013/02/05/197743.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/197743.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/197743.html</trackback:ping><description><![CDATA[<div style="margin: 0px; padding-top: 20px; padding-right: 10px; padding-bottom: 20px; word-wrap: break-word; word-break: normal; font-family: 宋体; font-size: 12px; line-height: 24px; background-color: #ffffff;"><div id="article_content" style="margin: 0px;"><p>文字色彩</p><p>可以用一个UIColor对象来定义文字的色彩。UIColor这个类提供了许多不同的方法，可以很轻松地调出任何颜色。你可以用静态方法来创建 颜色，这样它们会在停止使用后被释放。可以用灰度值、色相或者RGB复合值等多种形式来创建颜色。要创建一个简单的RGB色彩，可以指定一组4个浮点值， 分别对应红、绿、蓝和alpha值（透明度），取值均在0.0～1.0之间。这些值表示了0%（0.0）～100%（1.0）的范围：</p><ol style="margin: 0px; padding: 0px; list-style: none;"><li style="margin: 0px; padding: 0px;">UIColor&nbsp;*myWhiteTransparentColor&nbsp;=&nbsp;[&nbsp;UIColor&nbsp;<br />colorWithWhite:&nbsp;1.0&nbsp;alpha:&nbsp;0.50&nbsp;]; &nbsp;</li><li style="margin: 0px; padding: 0px;">&nbsp;</li><li style="margin: 0px; padding: 0px;">UIColor&nbsp;*myColorHue&nbsp;=&nbsp;[&nbsp;UIColor&nbsp;colorWithHue:&nbsp;120.0&nbsp;/&nbsp;360.0 &nbsp;</li><li style="margin: 0px; padding: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;saturation:&nbsp;0.75 &nbsp;</li><li style="margin: 0px; padding: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;brightness:&nbsp;0.50 &nbsp;</li><li style="margin: 0px; padding: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alpha:&nbsp;1.0 &nbsp;</li><li style="margin: 0px; padding: 0px;">]; &nbsp;</li><li style="margin: 0px; padding: 0px;">&nbsp;</li><li style="margin: 0px; padding: 0px;">UIColor&nbsp;*myColorRGB&nbsp;=&nbsp;[&nbsp;UIColor&nbsp;colorWithRed:&nbsp;0.75 &nbsp;</li><li style="margin: 0px; padding: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;green:&nbsp;1.0 &nbsp;</li><li style="margin: 0px; padding: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;blue:&nbsp;0.75 &nbsp;</li><li style="margin: 0px; padding: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alpha:&nbsp;1.0 &nbsp;</li><li style="margin: 0px; padding: 0px;">];&nbsp;</li></ol><p>如果你打算重用许多不同的UIColor对象，你也可以创建它们的实例：</p><ol style="margin: 0px; padding: 0px; list-style: none;"><li style="margin: 0px; padding: 0px;">UIColor&nbsp;*myWhiteTransparentColor&nbsp;=&nbsp;[&nbsp;[&nbsp;UIColor&nbsp;alloc&nbsp;] &nbsp;</li><li style="margin: 0px; padding: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;initWithWhite:&nbsp;1.0&nbsp;alpha:&nbsp;0.50 &nbsp;</li><li style="margin: 0px; padding: 0px;">]; &nbsp;</li><li style="margin: 0px; padding: 0px;">&nbsp;</li><li style="margin: 0px; padding: 0px;">UIColor&nbsp;*myColorHue&nbsp;=&nbsp;[&nbsp;[&nbsp;UIColor&nbsp;alloc&nbsp;] &nbsp;</li><li style="margin: 0px; padding: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;initWithHue:&nbsp;120.0&nbsp;/&nbsp;360.0 &nbsp;</li><li style="margin: 0px; padding: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;saturation:&nbsp;0.75 &nbsp;</li><li style="margin: 0px; padding: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;brightness:&nbsp;0.50 &nbsp;</li><li style="margin: 0px; padding: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alpha:&nbsp;1.0 &nbsp;</li><li style="margin: 0px; padding: 0px;">]; &nbsp;</li><li style="margin: 0px; padding: 0px;">&nbsp;</li><li style="margin: 0px; padding: 0px;">UIColor&nbsp;*myColorRGB&nbsp;=&nbsp;[&nbsp;[&nbsp;UIColor&nbsp;alloc&nbsp;]&nbsp;initWithRed:&nbsp;0.75 &nbsp;</li><li style="margin: 0px; padding: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;green:&nbsp;1.0 &nbsp;</li><li style="margin: 0px; padding: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;blue:&nbsp;0.75 &nbsp;</li><li style="margin: 0px; padding: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alpha:&nbsp;1.0 &nbsp;</li><li style="margin: 0px; padding: 0px;">];&nbsp;</li></ol><p>UIColor类还支持许多静态方法，可以创建系统颜色，这些颜色都经过iPhone的校正，以达到尽可能准确的地步。这些方法如下所示，均来自UIColor.h：</p><ol style="margin: 0px; padding: 0px; list-style: none;"><li style="margin: 0px; padding: 0px;">+&nbsp;(UIColor&nbsp;*)blackColor;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;0.0&nbsp;白色 &nbsp;</li><li style="margin: 0px; padding: 0px;">+&nbsp;(UIColor&nbsp;*)darkGrayColor;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;0.333&nbsp;白色 &nbsp;</li><li style="margin: 0px; padding: 0px;">+&nbsp;(UIColor&nbsp;*)lightGrayColor;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;0.667&nbsp;白色 &nbsp;</li><li style="margin: 0px; padding: 0px;">+&nbsp;(UIColor&nbsp;*)whiteColor;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;1.0&nbsp;白色 &nbsp;</li><li style="margin: 0px; padding: 0px;">+&nbsp;(UIColor&nbsp;*)grayColor;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;0.5&nbsp;白色 &nbsp;</li><li style="margin: 0px; padding: 0px;">+&nbsp;(UIColor&nbsp;*)redColor;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;1.0,&nbsp;0.0,&nbsp;0.0&nbsp;RGB &nbsp;</li><li style="margin: 0px; padding: 0px;">+&nbsp;(UIColor&nbsp;*)greenColor;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;0.0,&nbsp;1.0,&nbsp;0.0&nbsp;RGB &nbsp;</li><li style="margin: 0px; padding: 0px;">+&nbsp;(UIColor&nbsp;*)blueColor;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;0.0,&nbsp;0.0,&nbsp;1.0&nbsp;RGB &nbsp;</li><li style="margin: 0px; padding: 0px;">+&nbsp;(UIColor&nbsp;*)cyanColor;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;0.0,&nbsp;1.0,&nbsp;1.0&nbsp;RGB &nbsp;</li><li style="margin: 0px; padding: 0px;">+&nbsp;(UIColor&nbsp;*)yellowColor;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;1.0,&nbsp;1.0,&nbsp;0.0&nbsp;RGB &nbsp;</li><li style="margin: 0px; padding: 0px;">+&nbsp;(UIColor&nbsp;*)magentaColor;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;1.0,&nbsp;0.0,&nbsp;1.0&nbsp;RGB &nbsp;</li><li style="margin: 0px; padding: 0px;">+&nbsp;(UIColor&nbsp;*)orangeColor;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;1.0,&nbsp;0.5,&nbsp;0.0&nbsp;RGB &nbsp;</li><li style="margin: 0px; padding: 0px;">+&nbsp;(UIColor&nbsp;*)purpleColor;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;0.5,&nbsp;0.0,&nbsp;0.5&nbsp;RGB &nbsp;</li><li style="margin: 0px; padding: 0px;">+&nbsp;(UIColor&nbsp;*)brownColor;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;0.6,&nbsp;0.4,&nbsp;0.2&nbsp;RGB &nbsp;</li><li style="margin: 0px; padding: 0px;">+&nbsp;(UIColor&nbsp;*)clearColor;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;0.0&nbsp;白色,&nbsp;0.0&nbsp;alpha&nbsp;</li></ol><p>创建好UIColor对象之后，就可以将其赋给文本视图的色彩属性了：</p>textView.textColor&nbsp;=&nbsp;myColorHue;&nbsp;</div><div></div></div><img src ="http://www.cppblog.com/lauer3912/aggbug/197743.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2013-02-05 15:24 <a href="http://www.cppblog.com/lauer3912/archive/2013/02/05/197743.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>《移动应用开发解决方案》Embarcadero HTML 5 Builder </title><link>http://www.cppblog.com/lauer3912/archive/2013/01/08/197116.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Tue, 08 Jan 2013 08:31:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2013/01/08/197116.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/197116.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2013/01/08/197116.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/197116.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/197116.html</trackback:ping><description><![CDATA[<div><div>《移动应用开发解决方案》Embarcadero HTML 5 Builder</div> <div>2012年10月28日 &#8260; <a title="查看 最新素材 中的全部文章" href="http://www.renrensucai.com/archives/category/zuixinsucai" rel="category tag">最新素材</a>, <a title="查看 行业软件 中的全部文章" href="http://www.renrensucai.com/archives/category/zuixinsucai/softplug-ins-fonts-brushes-filter" rel="category tag">行业软件</a> &#8260; <a title="《《移动应用开发解决方案》Embarcadero HTML 5 Builder》上的评论" href="http://www.renrensucai.com/archives/18983#respond">暂无评论</a> &#8260; 被围观  324 views+ </div></div> <div jquery1357633033816="72"> <div id="entry" jquery1357633033816="71"> <p jquery1357633033816="70"><img id="aimg_70813" title="002364cf_medium.jpg" alt="002364cf_medium.jpg" src="http://www.rr-sc.com/data/attachment/forum/201210/28/080506fy5btkf56ylat5t0.jpg" width="422" original="http://www.rr-sc.com/data/attachment/forum/201210/28/080506fy5btkf56ylat5t0.jpg" loaded="true" /><br />Embarcadero HTML 5 Builder | 464.2 mb</p> <p>HTML5 Builder允许开发者在可视化IDE中使用Javascript、HTML5，jQuery  mobile以及CSS3开发Web和移动应用。关心跨平台移动支持的开发者，可以使用同一份公共HTML5/CSS3/JavaScript代码，支持iOS，Android，黑莓以及Windows  Phone。HTML5 Builder不仅仅关注客户端开发，它还集成了服务端PHP以及数据库（如MySQL）的支持。<br />HTML5  Builder是增强并重命名的RadPHP。通过对客户端解决方案的更多支持，尤其是对HTML5和CSS3的支持，我们感觉新名字更适合其新能力，并且更符合当前的市场。作为一个完整的端到端Web开发解决方案，HTML5  Builder继续支持PHP后端解决方案（具体讲，就是Zend框架以及数据访问组件）。</p> <p>HTML5 Builder is Embarcadero's Web and Mobile application development  solution enabling corporate and ISV developers to visually design and create  apps for Web, iOS, Android, BlackBerry and Windows Phone using a single HTML5,  CSS3, PHP and JavaScript codebase.</p> <p>HTML5 Builder is the replacement for RadPHP in the Embarcadero product  portfolio for Web and Mobile application platforms. With this groundbreaking new  developer solution you can now build web and mobile apps with a single codebase  using web standards - and deliver your apps to users via desktop and mobile Web  browsers or natively "on device" via Apple, Android, BlackBerry and Windows  Phone mobile app stores.</p> <p>About Embarcadero Technologies<br />Embarcadero Technologies, Inc. is a leading  provider of award-winning tools for application developers and database  professionals so they can design systems right, build them faster and run them  better, regardless of their platform or programming language. Ninety of the  Fortune 100 and an active community of more than three million users worldwide  rely on Embarcadero products to increase productivity, reduce costs, simplify  change management and compliance, and accelerate innovation. Founded in 1993,  Embarcadero is headquartered in San Francisco, with offices located around the  world.</p> <div></div></div> <div> <div><a href="http://www.rr-sc.com/thread-623-1-1.html" target="_blank"><img alt="VIP服务" src="http://www.rr-sc.com/data/attachment/forum/201110/15/155221l8p60l9n9ljenxv7.jpg" /></a></div></div></div><img src ="http://www.cppblog.com/lauer3912/aggbug/197116.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2013-01-08 16:31 <a href="http://www.cppblog.com/lauer3912/archive/2013/01/08/197116.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Parse .strings file with Python</title><link>http://www.cppblog.com/lauer3912/archive/2013/01/08/197108.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Tue, 08 Jan 2013 05:44:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2013/01/08/197108.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/197108.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2013/01/08/197108.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/197108.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/197108.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: Parse .strings file with PythonParse .strings file with Pythonup vote1down votefavoriteI'm trying to write a small Python script to parse the .strings file in my iPhone application project and determi...&nbsp;&nbsp;<a href='http://www.cppblog.com/lauer3912/archive/2013/01/08/197108.html'>阅读全文</a><img src ="http://www.cppblog.com/lauer3912/aggbug/197108.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2013-01-08 13:44 <a href="http://www.cppblog.com/lauer3912/archive/2013/01/08/197108.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Cocoa中检查文件目录是否有权限的方法</title><link>http://www.cppblog.com/lauer3912/archive/2013/01/07/197091.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Mon, 07 Jan 2013 15:24:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2013/01/07/197091.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/197091.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2013/01/07/197091.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/197091.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/197091.html</trackback:ping><description><![CDATA[<p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;">cocoa中虽然有[[NSFileManager defaultManager] fileExistsAtPath:filename]来检查文件是否可写的方法，但是对文件目录却不起作用，没办法只好自己写一个比较山寨的方法：</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;">bool IsDirectoryWritable(NSString *dir)<br />{<br />&nbsp;&nbsp;&nbsp; bool result = false;<br />&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp; if(![[NSFileManager defaultManager] fileExistsAtPath:dir])<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return result;<br />&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp; NSString* fileName = [dir stringByAppendingFormat:@"/&nbsp; _#t.txt"];<br />&nbsp;&nbsp;&nbsp; NSData *data = [fileName dataUsingEncoding:NSUTF8StringEncoding];<br />&nbsp;&nbsp;&nbsp; [data writeToFile:fileName atomically:NO];<br />&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp; result = [[NSFileManager defaultManager] fileExistsAtPath:fileName];<br />&nbsp;&nbsp;&nbsp; if(result)<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [[NSFileManager defaultManager] removeItemAtPath:fileName error:NULL];<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp; return true;<br />}<br /></p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;">这个方法的不好之处就是有可能用于尝试的fileName可能已经存在(虽然已经起的很奇怪了<img alt="快哭了" src="http://static.blog.csdn.net/xheditor/xheditor_emot/default/fastcry.gif" style="border: none;" />)，这样会导致返回结果不准确，也有可能测试文件创建成功了但是删除却失败了，那么也会导致下次测试不准确,。如果哪位高人有更好的办法，麻烦指教。</p><img src ="http://www.cppblog.com/lauer3912/aggbug/197091.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2013-01-07 23:24 <a href="http://www.cppblog.com/lauer3912/archive/2013/01/07/197091.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Cocoa中打开文件和文件夹的方法</title><link>http://www.cppblog.com/lauer3912/archive/2013/01/07/197090.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Mon, 07 Jan 2013 15:23:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2013/01/07/197090.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/197090.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2013/01/07/197090.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/197090.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/197090.html</trackback:ping><description><![CDATA[<p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;">很多程序有这样的功能，双击某个图片可以打开源文件，右键菜单中的Show in Finder功能，Cocoa中对这块支持较好，有现成的方法：</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;">[[NSWorkspace sharedWorkspace] openFile:fileName];</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;">[[NSWorkspace sharedWorkspace] selectFile:fileName inFileViewerRootedAtPath:path];&nbsp; // 如果只打开目录不需要选中具体文件，fileName可为nil。</p><img src ="http://www.cppblog.com/lauer3912/aggbug/197090.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2013-01-07 23:23 <a href="http://www.cppblog.com/lauer3912/archive/2013/01/07/197090.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Windows 8版扫雷更新 添加30s广告</title><link>http://www.cppblog.com/lauer3912/archive/2012/12/26/196669.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Wed, 26 Dec 2012 02:32:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2012/12/26/196669.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/196669.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2012/12/26/196669.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/196669.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/196669.html</trackback:ping><description><![CDATA[http://www.cnbeta.com/articles/219634.htm<br /><br /><p><strong>感谢<a href="http://bbs.windowsparty.com/index.aspx" target="_blank">GZX</a>的投递</strong><br />
今天刚刚收到Windows 8商店的提示，扫雷可以更新了，于是兴致勃勃的下载最新版的Windows 8扫雷，截图给大家看。<br />
从开始屏幕上看，扫雷的应用磁帖并没有发生太大的变化。</p>
		<img src="http://img.cnbeta.com/newsimg/121226/064618069541979.jpg" title="photo-media" style="border:0px;vertical-align:middle;max-width:550px;"  alt="" /><br />
但是打开应用之后，就会发现有了不一样的地方。<br />
在主题部分，你将会看到新的主题&#8220;传统主题&#8221;。<br />
<img src="http://img.cnbeta.com/newsimg/121226/06461811571402259.jpg" title="photo-media" style="border:0px;vertical-align:middle;max-width:550px;"  alt="" /><br />
当你点击了传统主题后，游戏选项卡部分将会变为传统的扫雷样式。<br />
<img src="http://img.cnbeta.com/newsimg/121226/06461821074809530.jpg" title="photo-media" style="border:0px;vertical-align:middle;max-width:550px;"  alt="" /><br />
随意进入一个选项卡，就可以看到我们熟悉的界面<br />
<img src="http://img.cnbeta.com/newsimg/121226/0646193689516706.jpg" title="photo-media" style="border:0px;vertical-align:middle;max-width:550px;"  alt="" /><br />
进入自定义模式后，我们可以看到三个选项条，分别为：长、宽以及雷数，最大值如图所示<br />
<img src="http://img.cnbeta.com/newsimg/121226/0646194215626351.jpg" title="photo-media" style="border:0px;vertical-align:middle;max-width:550px;"  alt="" /><br />
进入冒险模式后，我们可以发现与之前的版本并没有太大变化<br />
<img src="http://img.cnbeta.com/newsimg/121226/0646195106505911.jpg" title="photo-media" style="border:0px;vertical-align:middle;max-width:550px;"  alt="" /><br />
出现了广告界面则是在&#8220;每日挑战&#8221;中<br />
<img src="http://img.cnbeta.com/newsimg/121226/06462061971465392.jpg" title="photo-media" style="border:0px;vertical-align:middle;max-width:550px;"  alt="" /><br />
打开&#8220;每日挑战&#8221;，我们可以看到界面的右侧多了一个广告显示的位置，如下图红框内所示<br />
<img src="http://img.cnbeta.com/newsimg/121226/0646207786649801.jpg" title="photo-media" style="border:0px;vertical-align:middle;max-width:550px;"  alt="" /><br />
而当你选择了任意一个模式后，就被强迫观看30s的广告<br />
<img src="http://img.cnbeta.com/newsimg/121226/06462181208044522.jpg" title="photo-media" style="border:0px;vertical-align:middle;max-width:550px;"  alt="" /><br />
视频缓冲阶段，你会看到如下文字：&#8220;Thanks to our sponsors, this game is free（感谢我们的赞助商，本游戏完全免费）&#8221;<br />
<img src="http://img.cnbeta.com/newsimg/121226/06462191051154769.jpg" title="photo-media" style="border:0px;vertical-align:middle;max-width:550px;"  alt="" /><br />
而观看视频时，它还会提示你游戏开始的时间，注意中下部<br />
进入游戏后，则与之前介绍的界面完全类似<br />
<img src="http://img.cnbeta.com/newsimg/121226/064621102012518811.jpg" title="photo-media" style="border:0px;vertical-align:middle;max-width:550px;"  alt="" /><br />
<br />
这里要提示的是，每次打开扫雷应用的&#8220;每日挑战&#8221;，你只需要观看一次视频广告（每次的广告均有所不同），就可以体验全部的三个模式<br />
&nbsp;<br />
那么，你准备好升级你的扫雷了么？<img src ="http://www.cppblog.com/lauer3912/aggbug/196669.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2012-12-26 10:32 <a href="http://www.cppblog.com/lauer3912/archive/2012/12/26/196669.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title> IOS学习笔记12—UITabBarController ,重点在于灵活设置导航控制器。</title><link>http://www.cppblog.com/lauer3912/archive/2012/12/26/196668.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Wed, 26 Dec 2012 02:31:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2012/12/26/196668.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/196668.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2012/12/26/196668.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/196668.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/196668.html</trackback:ping><description><![CDATA[<div id="article_content" class="article_content">

<p class="p1"><span style="font-family:Comic Sans MS; font-size:18px">UITabBarController是选项卡栏导航控制器，显示效果是在页面底部有多个选项卡，通过点击不同选项卡可以在不同的ViewController之间进行切换。</span></p>
<p class="p2"><span style="font-family:Comic Sans MS; font-size:18px"><br />
</span></p>
<p class="p1"><span style="font-family:Comic Sans MS; font-size:18px">这种对象的层次结构至少包含6个对象：</span></p>
<p class="p1"><span style="font-family:Comic Sans MS; font-size:18px">一个UITabBarController；</span></p>
<p class="p1"><span style="font-family:Comic Sans MS; font-size:18px">两个UIViewController；</span></p>
<p class="p1"><span style="font-family:Comic Sans MS; font-size:18px">一个UITabBar；</span></p>
<p class="p1"><span style="font-family:Comic Sans MS; font-size:18px">两个UITabBarItem；</span></p>
<p class="p2"><span style="font-family:Comic Sans MS; font-size:18px"><br />
</span></p>
<p class="p1"><span style="font-family:Comic Sans MS; font-size:18px">UITabBarController
是选项卡栏视图控制器，UITabBar是底部两个UITabBarItem的容器，管理两个UITabBarItem，每个UITabBarItem对
应一个UIViewController，然后每个UIViewController都有自己的视图和视图控制器。</span></p>
<p class="p2"><span style="font-family:Comic Sans MS; font-size:18px"><br />
</span></p>
<p class="p1"><span style="font-family:Comic Sans MS; font-size:18px">UITabBarController中有一个viewControllers属性，这是一个NSArray，包含选项卡控制器的视图控制器</span></p>
<p class="p2"><span style="font-family:Comic Sans MS; font-size:18px"><br />
</span></p>
<p class="p1"><span style="font-family:Comic Sans MS; font-size:18px">下面来用代码创建一个UITabBarController：</span></p>
<p class="p1"><span style="font-family:Comic Sans MS; font-size:18px">下面是工程结构：</span></p>
<p class="p1"><span style="font-family:Comic Sans MS; font-size:18px"><img src="http://my.csdn.net/uploads/201207/18/1342582407_8811.png" alt="" /></span></p>

<p class="p1"><span style="font-family:Comic Sans MS; font-size:18px">首先创建两个带xib文件的ViewController，分别为FirstViewController和SecondViewController</span></p>
<p class="p2"><span style="font-family:Comic Sans MS; font-size:18px"><span class="s1">然后在AppDelegate.h中声明</span><span class="s2">@property</span> (<span class="s2">strong</span>,<span class="s2">nonatomic</span>)
<span class="s3">UITabBarController</span> *tabBarController;，并添加协议<span class="s3">UITabBarControllerDelegate</span></span></p>
<p class="p3"><span style="font-family:Comic Sans MS; font-size:18px"><br />
</span></p>
<p class="p1"><span style="font-family:Comic Sans MS; font-size:18px">在.m中实现如下代码：</span></p>

<div class="dp-highlighter bg_cpp"><div class="bar"><div class="tools"><strong>[cpp]</strong> <a href="http://blog.csdn.net/tangren03/article/details/7758511#" class="ViewSource" title="view plain">view plain</a><a href="http://blog.csdn.net/tangren03/article/details/7758511#" class="CopyToClipboard" title="copy">copy</a></div></div><ol class="dp-cpp" start="1"><li class="alt"><span><span>-&nbsp;(</span><span class="datatypes">BOOL</span><span>)application:(UIApplication&nbsp;*)application&nbsp;didFinishLaunchingWithOptions:(NSDictionary&nbsp;*)launchOptions&nbsp;&nbsp;</span></span></li><li class=""><span>{&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;self.window&nbsp;=&nbsp;[[[UIWindow&nbsp;alloc]&nbsp;initWithFrame:[[UIScreen&nbsp;mainScreen]&nbsp;bounds]]&nbsp;autorelease];&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;Override&nbsp;point&nbsp;for&nbsp;customization&nbsp;after&nbsp;application&nbsp;launch.</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//第一个tab的viewController</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;FirstViewController&nbsp;*firstViewController&nbsp;=&nbsp;[[FirstViewController&nbsp;alloc]init];&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//如果在这里指定tabitem标题，则在FirstViewController中指定self.tabBarItem.title则不生效&nbsp;&nbsp;&nbsp;</span><span>&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;firstViewController.title&nbsp;=&nbsp;@<span class="string">"First&nbsp;view"</span><span>;&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;UITabBarItem&nbsp;*firstItem&nbsp;=&nbsp;[[UITabBarItem&nbsp;alloc]initWithTitle:@<span class="string">"First"</span><span>&nbsp;image:nil&nbsp;tag:1];&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;[firstItem&nbsp;setFinishedSelectedImage:[UIImage&nbsp;imageNamed:@<span class="string">"p1"</span><span>]&nbsp;withFinishedUnselectedImage:[UIImage&nbsp;imageNamed:@</span><span class="string">"p1_f"</span><span>]];&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;firstViewController.tabBarItem&nbsp;=&nbsp;firstItem;&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;SecondViewController&nbsp;*secondViewController&nbsp;=&nbsp;[[SecondViewController&nbsp;alloc]init];&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//构建TabBarItem</span><span>&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;UITabBarItem&nbsp;*secondItem&nbsp;=&nbsp;[[UITabBarItem&nbsp;alloc]initWithTitle:@<span class="string">"Second"</span><span>&nbsp;image:nil&nbsp;tag:2];&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//设置选中和非选中状态下的图片</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;[secondItem&nbsp;setFinishedSelectedImage:[UIImage&nbsp;imageNamed:@<span class="string">"p2_f"</span><span>]&nbsp;withFinishedUnselectedImage:[UIImage&nbsp;imageNamed:@</span><span class="string">"p2"</span><span>]];&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//右上角小图标</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;[secondItem&nbsp;setBadgeValue:@<span class="string">"2"</span><span>];&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//指定tabBarItem</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;secondViewController.tabBarItem&nbsp;=&nbsp;secondItem;&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;[secondItem&nbsp;release];&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//构建UITabBarController并指定代理为本身</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;self.tabBarController&nbsp;=&nbsp;[[[UITabBarController&nbsp;alloc]init]&nbsp;autorelease];&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;self.tabBarController.delegate&nbsp;=&nbsp;self;&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//为UITabBarController添加TabBarItem</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;self.tabBarController.viewControllers&nbsp;=&nbsp;[NSArray&nbsp;arrayWithObjects:firstViewController,secondViewController,&nbsp;nil];&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;[firstViewController&nbsp;release];&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;[secondViewController&nbsp;release];&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//设置选中哪个tab</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span><span class="comment">//&nbsp;&nbsp;&nbsp;&nbsp;[self.tabBarController&nbsp;setSelectedIndex:0];</span><span>&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//指定根视图</span><span>&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;self.window.rootViewController&nbsp;&nbsp;=&nbsp;self.tabBarController;&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;self.window.backgroundColor&nbsp;=&nbsp;[UIColor&nbsp;whiteColor];&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;[self.window&nbsp;makeKeyAndVisible];&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">return</span><span>&nbsp;YES;&nbsp;&nbsp;</span></span></li><li class="alt"><span>}&nbsp;&nbsp;</span></li></ol></div><br />
<br />

<span style="font-family:Comic Sans MS; font-size:18px"><img src="http://my.csdn.net/uploads/201207/18/1342582466_5909.png" alt="" /><img src="http://my.csdn.net/uploads/201207/18/1342582471_3677.png" alt="" /><br />
</span>
<p class="p1"><span style="font-family:Comic Sans MS; font-size:18px"><br /></span></p>

</div><img src ="http://www.cppblog.com/lauer3912/aggbug/196668.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2012-12-26 10:31 <a href="http://www.cppblog.com/lauer3912/archive/2012/12/26/196668.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Lua 语言简单入门</title><link>http://www.cppblog.com/lauer3912/archive/2012/11/29/195799.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Thu, 29 Nov 2012 08:32:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2012/11/29/195799.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/195799.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2012/11/29/195799.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/195799.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/195799.html</trackback:ping><description><![CDATA[<p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;">　　在这篇文章中，我想向大家介绍如何进行Lua程序设计。我假设大家都学过至少一门编程语言，比如Basic或C，特别是C。因为Lua的最大用途是在宿主程序中作为脚本使用的。</p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;">　　Lua 的语法比较简单，学习起来也比较省力，但功能却并不弱。</p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;">　　在Lua中，一切都是变量，除了关键字。请记住这句话。</p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;"><strong>I. 首先是注释</strong></p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;">　　写一个程序，总是少不了注释的。<br />　　在Lua中，你可以使用单行注释和多行注释。<br />　　单行注释中，连续两个减号"--"表示注释的开始，一直延续到行末为止。相当于C++语言中的"//"。<br />　　多行注释中，由"--[["表示注释开始，并且一直延续到"]]"为止。这种注释相当于C语言中的"/*&#8230;*/"。在注释当中，"[["和"]]"是可以嵌套的。</p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;"><strong>II. Lua编程</strong></p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;">　　经典的"Hello world"的程序总是被用来开始介绍一种语言。在Lua中，写一个这样的程序很简单：<br />　　print("Hello world")<br />　　在Lua中，语句之间可以用分号"；"隔开，也可以用空白隔开。一般来说，如果多个语句写在同一行的话，建议总是用分号隔开。<br />　　Lua 有好几种程序控制语句，如：</p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;">　　条件控制：if 条件 then &#8230; elseif 条件 then &#8230; else &#8230; end<br />　　While循环：while 条件 do &#8230; end<br />　　Repeat循环：repeat &#8230; until 条件<br />　　For循环：for 变量 = 初值，终点值，步进 do &#8230; end<br />　　For循环：for 变量1，变量2，&#8230; ，变量N in表或枚举函数 do &#8230; end</p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;">　　注意一下，for的循环变量总是只作用于for的局部变量，你也可以省略步进值，这时候，for循环会使用1作为步进值。<br />　　你可以用break来中止一个循环。<br />　　如果你有程序设计的基础，比如你学过Basic，C之类的，你会觉得Lua也不难。但Lua有几个地方是明显不同于这些程序设计语言的，所以请特别注意。</p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;">　　．语句块<br />　　　　语句块在C++中是用"{"和"}"括起来的，在Lua中，它是用do 和 end 括起来的。比如：&nbsp;<br />　　　　do print("Hello") end<br />　　　　你可以在 函数 中和 语句块 中定局部变量。</p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;">　　．赋值语句<br />　　　　赋值语句在Lua被强化了。它可以同时给多个变量赋值。<br />　　　　例如：<br />　　　　a,b,c,d=1,2,3,4<br />　　　　甚至是：<br />　　　　a,b=b,a -- 多么方便的交换变量功能啊。<br />　　　　在默认情况下，变量总是认为是全局的。假如你要定义局部变量，则在第一次赋值的时候，需要用local说明。比如：<br />　　　　local a,b,c = 1,2,3 -- a,b,c都是局部变量</p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;">　　．数值运算<br />　　　　和C语言一样，支持 +, -, *, /。但Lua还多了一个"^"。这表示指数乘方运算。比如2^3 结果为8, 2^4结果为16。<br />　　　　连接两个字符串，可以用".."运处符。如：<br />　　　　"This a " .. "string." -- 等于 "this a string"</p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;">　　．比较运算<br />　　　　&lt; &gt; &lt;= &gt;= == ~=<br />　　　　分别表示 小于，大于，不大于，不小于，相等，不相等<br />　　　　所有这些操作符总是返回true或false。<br />　　　　对于Table，Function和Userdata类型的数据，只有 == 和 ~=可以用。相等表示两个变量引用的是同一个数据。比如：<br />　　　　a={1,2}<br />　　　　b=a<br />　　　　print(a==b, a~=b) -- true, false<br />　　　　a={1,2}<br />　　　　b={1,2}<br />　　　　print(a==b, a~=b) -- false, true</p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;">　　．逻辑运算<br />　　　　and, or, not<br />　　　　其中，and 和 or 与C语言区别特别大。<br />　　　　在这里，请先记住，在Lua中，只有false和nil才计算为false，其它任何数据都计算为true，0也是true！<br />　　　　and 和 or的运算结果不是true和false，而是和它的两个操作数相关。<br />　　　　a and b：如果a为false，则返回a；否则返回b<br />　　　　a or b：如果 a 为true，则返回a；否则返回b</p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;">　　　　举几个例子：<br />　　　　 print(4 and 5) --&gt; 5<br />　　　　 print(nil and 13) --&gt; nil<br />　　　　 print(false and 13) --&gt; false<br />　　　　 print(4 or 5) --&gt; 4<br />　　　　 print(false or 5) --&gt; 5</p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;">　　　　在Lua中这是很有用的特性，也是比较令人混洧的特性。<br />　　　　我们可以模拟C语言中的语句：x = a? b : c，在Lua中，可以写成：x = a and b or c。<br />　　　　最有用的语句是： x = x or v，它相当于：if not x then x = v end 。</p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;">　　．运算符优先级，从高到低顺序如下：<br />　　　　^<br />　　　　not - （一元运算）<br />　　　　 * /<br />　　　　 + -<br />　　　　 ..（字符串连接）<br />　　　　 &lt; &gt; &lt;= &gt;= ~= ==<br />　　　　 and<br />　　　　 or</p><div>==========================================================<br /><table width="96%" align="center" style="font-family: STHeiti;"><tbody><tr><td height="254" style="font-size: 14px; line-height: 25px;"><p>&nbsp;</p><p><strong>III. 关键字</strong></p><p>　　关键字是不能做为变量的。Lua的关键字不多，就以下几个：<br />　　and break do else elseif<br />　　end false for function if<br />　　in local nil not or<br />　　repeat return then true until　while</p><p><strong>IV. 变量类型</strong></p><p>　　怎么确定一个变量是什么类型的呢？大家可以用type()函数来检查。Lua支持的类型有以下几种：</p><p>　　Nil 空值，所有没有使用过的变量，都是nil。nil既是值，又是类型。<br />　　Boolean 布尔值<br />　　Number 数值，在Lua里，数值相当于C语言的double<br />　　String 字符串，如果你愿意的话，字符串是可以包含'\0'字符的<br />　　Table 关系表类型，这个类型功能比较强大，我们在后面慢慢说。<br />　　Function 函数类型，不要怀疑，函数也是一种类型，也就是说，所有的函数，它本身就是一个变量。<br />　　Userdata 嗯，这个类型专门用来和Lua的宿主打交道的。宿主通常是用C和C++来编写的，在这种情况下，Userdata可以是宿主的任意数据类型，常用的有Struct和指针。<br />　　Thread　　 线程类型，在Lua中没有真正的线程。Lua中可以将一个函数分成几部份运行。如果感兴趣的话，可以去看看Lua的文档。</p><p><strong>V. 变量的定义</strong></p><p>　　所有的语言，都要用到变量。在Lua中，不管你在什么地方使用变量，都不需要声明，并且所有的这些变量总是全局变量，除非，你在前面加上"local"。<br />　　这一点要特别注意，因为你可能想在函数里使用局部变量，却忘了用local来说明。<br />　　至于变量名字，它是大小写相关的。也就是说，A和a是两个不同的变量。<br />　　定义一个变量的方法就是赋值。"＝"操作就是用来赋值的<br />　　我们一起来定义几种常用类型的变量吧。<br />　　A. Nil<br />　　　　正如前面所说的，没有使用过的变量的值，都是Nil。有时候我们也需要将一个变量清除，这时候，我们可以直接给变量赋以nil值。如：<br />　　　　var1=nil -- 请注意 nil 一定要小写</p><p>　　B. Boolean<br />　　　　布尔值通常是用在进行条件判断的时候。布尔值有两种：true 和 false。在Lua中，只有false和nil才被计算为false，而所有任何其它类型的值，都是true。比如0，空串等等，都是true。不要被C语言的习惯所误导，0在Lua中的的确确是true。你也可以直接给一个变量赋以Boolean类型的值，如：<br />　　　　varboolean = true</p><p>　　C. Number<br />　　　　在Lua中，是没有整数类型的，也不需要。一般情况下，只要数值不是很大（比如不超过100,000,000,000,000），是不会产生舍入误差的。在很多CPU上，实数的运算并不比整数慢。<br />　　　　实数的表示方法，同C语言类似，如：<br />　　　　4 0.4 4.57e-3 0.3e12 5e+20</p><p>　　D. String<br />　　　　字符串，总是一种非常常用的高级类型。在Lua中，你可以非常方便的定义很长很长的字符串。<br />　　　　字符串在Lua中有几种方法来表示，最通用的方法，是用双引号或单引号来括起一个字符串的，如：<br />　　　　"This is a string."<br />　　　　和C语言相同的，它支持一些转义字符，列表如下：<br />　　　　\a bell<br />　　　　\b back space<br />　　　　\f form feed<br />　　　　\n newline<br />　　　　\r carriage return<br />　　　　\t horizontal tab<br />　　　　\v vertical tab<br />　　　　\\ backslash<br />　　　　\" double quote<br />　　　　\' single quote<br />　　　　\[ left square bracket<br />　　　　\] right square bracket</p><p>　　　　由于这种字符串只能写在一行中，因此，不可避免的要用到转义字符。加入了转义字符的串，看起来实在是不敢恭维，比如：<br />　　　　"one line\nnext line\n\"in quotes\", 'in quotes'"<br />　　　　一大堆的"\"符号让人看起来很倒胃口。如果你与我有同感，那么，我们在Lua中，可以用另一种表示方法：用"[["和"]]"将多行的字符串括起来，如：<br />　　　　page = [[<br />　　　　&lt;HTML&gt;<br />　　　　　　&lt;HEAD&gt;<br />　　　　　　　　&lt;TITLE&gt;An HTML Page&lt;/TITLE&gt;<br />　　　　　　&lt;/HEAD&gt;<br />　　　　　　&lt;BODY&gt;<br />　　　　　　　　&lt;A HREF="<a href="http://www.lua.org%22%3Elua%3C/A" style="color: #006699;">http://www.lua.org"&gt;Lua&lt;/A</a>&gt;<br />　　　　　　　　[[a text between double brackets]]<br />　　　　　　&lt;/BODY&gt;<br />　　　　&lt;/HTML&gt;<br />　　　　]]</p><p>　　　　值得注意的是，在这种字符串中，如果含有单独使用的"[["或"]]"就仍然得用"\["或"\]"来避免歧义。当然，这种情况是极少会发生的。</p><div></div></td></tr></tbody></table><br /><br />==================================================================<br /><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;">E. Table<br />　　　　关系表类型，这是一个很强大的类型。我们可以把这个类型看作是一个数组。只是C语言的数组，只能用正整数来作索引；在Lua中，你可以用任意类型来作数组的索引，除了nil。同样，在C语言中，数组的内容只允许一种类型；在Lua中，你也可以用任意类型的值来作数组的内容，除了nil。<br />　　　　Table的定义很简单，它的主要特征是用"{"和"}"来括起一系列数据元素的。比如：</p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;">　　　　T1 = {} -- 定义一个空表<br />　　　　T1[1]=10 -- 然后我们就可以象C语言一样来使用它了。<br />　　　　T1["John"]={Age=27, Gender="Male"}<br />　　　　这一句相当于：<br />　　　　T1["John"]={} -- 必须先定义成一个表，还记得未定义的变量是nil类型吗<br />　　　　T1["John"]["Age"]=27<br />　　　　T1["John"]["Gender"]="Male"<br />　　　　当表的索引是字符串的时候，我们可以简写成：<br />　　　　T1.John={}<br />　　　　T1.John.Age=27<br />　　　　T1.John.Gender="Male"<br />　　　　或<br />　　　　T1.John{Age=27, Gender="Male"}<br />　　　　这是一个很强的特性。</p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;">　　　　在定义表的时候，我们可以把所有的数据内容一起写在"{"和"}"之间，这样子是非常方便，而且很好看。比如，前面的T1的定义，我们可以这么写：</p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;">　　　　T1=<br />　　　　{<br />　　　　　　10, -- 相当于 [1] = 10<br />　　　　　　[100] = 40,<br />　　　　　　John= -- 如果你原意，你还可以写成：["John"] =<br />　　　　　　{<br />　　　　　　　　Age=27, -- 如果你原意，你还可以写成：["Age"] =27<br />　　　　　　　　Gender=Male -- 如果你原意，你还可以写成：["Gender"] =Male<br />　　　　　　},<br />　　　　　　20 -- 相当于 [2] = 20<br />　　　　}</p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;">　　　　看起来很漂亮，不是吗？我们在写的时候，需要注意三点：<br />　　　　第一，所有元素之间，总是用逗号"，"隔开；<br />　　　　第二，所有索引值都需要用"["和"]"括起来；如果是字符串，还可以去掉引号和中括号；<br />　　　　第三，如果不写索引，则索引就会被认为是数字，并按顺序自动从1往后编；</p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;">　　　　表类型的构造是如此的方便，以致于常常被人用来代替配置文件。是的，不用怀疑，它比ini文件要漂亮，并且强大的多。</p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;">　　F. Function<br />　　　　函数，在Lua中，函数的定义也很简单。典型的定义如下：<br />　　　　function add(a,b) -- add 是函数名字，a和b是参数名字<br />　　　　 return a+b -- return 用来返回函数的运行结果<br />　　　　end</p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;">　　　　请注意，return语言一定要写在end之前。假如你非要在中间放上一句return，那么请写成：do return end。<br />　　　　还记得前面说过，函数也是变量类型吗？上面的函数定义，其实相当于：<br />　　　　add = function (a,b) return a+b end<br />　　　　当你重新给add赋值时，它就不再表示这个函数了。你甚至可以赋给add任意数据，包括nil （这样，你就清除了add变量）。Function是不是很象C语言的函数指针呢？</p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;">　　　　和C语言一样，Lua的函数可以接受可变参数个数，它同样是用"&#8230;"来定义的，比如：<br />　　　　function sum (a,b,&#8230;)<br />　　　　如果想取得&#8230;所代表的参数，可以在函数中访问arg局部变量（表类型）得到。<br />　　　　如 sum(1,2,3,4)<br />　　　　则，在函数中，a = 1, b = 2, arg = {3, 4}<br />　　　　更可贵的是，它可以同时返回多个结果，比如：<br />　　　　function s()<br />　　　　　　return 1,2,3,4<br />　　　　end<br />　　　　a,b,c,d = s() -- 此时，a = 1, b = 2, c = 3, d = 4<br />前面说过，表类型可以拥有任意类型的值，包括函数！因此，有一个很强大的特性是，拥有函数的表，哦，我想更恰当的应该说是对象吧。Lua可以使用面向对象编程了。不信？那我举例如下：</p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;">　　　　t =<br />　　　　{<br />　　　　 Age = 27<br />　　　　 add = function(self, n) self.Age = self.Age+n end<br />　　　　}<br />　　　　print(t.Age) -- 27<br />　　　　t.add(t, 10)<br />　　　　print(t.Age) -- 37</p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;">　　　　不过，t.add(t,10) 这一句实在是有点土对吧？没关系，在Lua中，你可以简写成：<br />　　　　t:add(10) -- 相当于 t.add(t,10)</p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;">　　G. Userdata 和 Thread<br />　　　　这两个类型的话题，超出了本文的内容，就不打算细说了。</p>===========================================================<br /><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;"><strong>VI. 结束语</strong></p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;">　　就这么结束了吗？当然不是，接下来，需要用Lua解释器，来帮助你理解和实践了。这篇小文只是帮助你大体了解Lua的语法。如果你有编程基础，相信会很快对Lua上手了。<br />　　就象C语言一样，Lua提供了相当多的标准函数来增强语言的功能。使用这些标准函数，你可以很方便的操作各种数据类型，并处理输入输出。有关这方面的信息，你可以参考《Programming in Lua 》一书，你可以在网络上直接观看电子版，网址为：<a href="http://www.lua.org/pil/index.html" style="color: #006699;">http://www.lua.org/pil/index.html</a><br />　　当然，Lua的最强大的功能是能与宿主程序亲蜜无间的合作，因此，下一篇文章，我会告诉大家，如何在你的程序中使用Lua语言作为脚本，使你的程序和Lua脚本进行交互。</p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;"><strong>使用流程</strong></p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;"><strong>1. 函数的使用</strong></p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; 以下程序演示了如何在Lua中使用函数, 及局部变量<br />例e02.lua<br />-- functions&nbsp;<br />function pythagorean(a, b)&nbsp;<br />local c2 = a^2 + b^2&nbsp;<br />return sqrt(c2)&nbsp;<br />end&nbsp;<br />print(pythagorean(3,4))</p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;">运行结果<br />5</p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;">程序说明<br />在Lua中函数的定义格式为:<br />function 函数名(参数)<br />...<br />end<br />&nbsp;&nbsp;&nbsp; 与Pascal语言不同, end不需要与begin配对, 只需要在函数结束后打个end就可以了.本例函数的作用是已知直角三角形直角边, 求斜边长度. 参数a,b分别表示直角边长,<br />&nbsp;&nbsp;&nbsp; 在函数内定义了local形变量用于存储斜边的平方. 与C语言相同, 定义在函数内的代码不会被直接执行, 只有主程序调用时才会被执行.<br />&nbsp;&nbsp;&nbsp; local表示定义一个局部变量, 如果不加local刚表示c2为一个全局变量, local的作用域是在最里层的end和其配对的关键字之间, 如if ... end, while ... end等。全局变量的作用域是整个程序。</p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;"><strong>2. 循环语句</strong></p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;">例e03.lua<br />-- Loops&nbsp;<br />for i=1,5 do&nbsp;<br />print("i is now " .. i)&nbsp;<br />end</p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;">运行结果<br />i is now 1&nbsp;<br />i is now 2&nbsp;<br />i is now 3&nbsp;<br />i is now 4&nbsp;<br />i is now 5</p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;">程序说明<br />&nbsp;&nbsp;&nbsp; 这里偶们用到了for语句<br />for 变量 = 参数1, 参数2, 参数3 do<br />循环体<br />end<br />&nbsp;&nbsp;&nbsp; 变量将以参数3为步长, 由参数1变化到参数2<br />例如:&nbsp;<br />for i=1,f(x) do print(i) end<br />for i=10,1,-1 do print(i) end</p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; 这里print("i is now " .. i)中，偶们用到了..，这是用来连接两个字符串的，偶在(1)的试试看中提到的，不知道你们答对了没有。虽然这里i是一个整型量，Lua在处理的时候会自动转成字符串型，不需偶们费心。</p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;"><strong>3. 条件分支语句</strong></p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;">例e04.lua<br />-- Loops and conditionals&nbsp;<br />for i=1,5 do<br />print(&#8220;i is now &#8220; .. i)<br />if i &lt; 2 then&nbsp;<br />print(&#8220;small&#8221;)&nbsp;<br />elseif i &lt; 4 then&nbsp;<br />print(&#8220;medium&#8221;)&nbsp;<br />else&nbsp;<br />print(&#8220;big&#8221;)&nbsp;<br />end&nbsp;<br />end</p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;">运行结果<br />i is now 1&nbsp;<br />small&nbsp;<br />i is now 2&nbsp;<br />medium&nbsp;<br />i is now 3&nbsp;<br />medium&nbsp;<br />i is now 4&nbsp;<br />big&nbsp;<br />i is now 5&nbsp;<br />big</p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;">程序说明<br />&nbsp;&nbsp;&nbsp; if else用法比较简单, 类似于C语言, 不过此处需要注意的是整个if只需要一个end,哪怕用了多个elseif, 也是一个end.<br />例如<br />if op == "+" then<br />r = a + b<br />elseif op == "-" then<br />r = a - b<br />elseif op == "*" then<br />r = a*b<br />elseif op == "/" then<br />r = a/b<br />else<br />error("invalid operation")<br />end</p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;"><br /><strong>4.试试看</strong></p><p style="font-family: STHeiti; line-height: 25px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; Lua中除了for循环以外, 还支持多种循环, 请用while...do和repeat...until改写本文中的for程序。<br /><p><strong>数组的使用</strong></p><p><strong>1.简介</strong></p><p>&nbsp;&nbsp;&nbsp; Lua语言只有一种基本数据结构, 那就是table, 所有其他数据结构如数组啦,类啦, 都可以由table实现.</p><p><strong>2.table的下标</strong></p><p>例e05.lua<br />-- Arrays&nbsp;<br />myData = {}&nbsp;<br />myData[0] = &#8220;foo&#8221;&nbsp;<br />myData[1] = 42</p><p>-- Hash tables&nbsp;<br />myData[&#8220;bar&#8221;] = &#8220;baz&#8221;</p><p>-- Iterate through the&nbsp;<br />-- structure&nbsp;<br />for key, value in myData do&nbsp;<br />print(key .. &#8220;=&#8220; .. value)&nbsp;<br />end</p><p>输出结果<br />0=foo&nbsp;<br />1=42&nbsp;<br />bar=baz</p><p>程序说明<br />&nbsp;&nbsp;&nbsp; 首先定义了一个table myData={}, 然后用数字作为下标赋了两个值给它. 这种定义方法类似于C中的数组, 但与数组不同的是, 每个数组元素不需要为相同类型,就像本例中一个为整型, 一个为字符串.</p><p>&nbsp;&nbsp;&nbsp; 程序第二部分, 以字符串做为下标, 又向table内增加了一个元素. 这种table非常像STL里面的map. table下标可以为Lua所支持的任意基本类型, 除了nil值以外.</p><p>&nbsp;&nbsp;&nbsp; Lua对Table占用内存的处理是自动的, 如下面这段代码<br />a = {}<br />a["x"] = 10<br />b = a -- `b' refers to the same table as `a'<br />print(b["x"]) --&gt; 10<br />b["x"] = 20<br />print(a["x"]) --&gt; 20<br />a = nil -- now only `b' still refers to the table<br />b = nil -- now there are no references left to the table<br />&nbsp;&nbsp;&nbsp; b和a都指向相同的table, 只占用一块内存, 当执行到a = nil时, b仍然指向table,<br />&nbsp;&nbsp;&nbsp; 而当执行到b=nil时, 因为没有指向table的变量了, 所以Lua会自动释放table所占内存</p><p><strong>3.Table的嵌套</strong></p><p>&nbsp;&nbsp;&nbsp; Table的使用还可以嵌套，如下例<br />例e06.lua<br />-- Table &#8216;constructor&#8217;&nbsp;<br />myPolygon = {&nbsp;<br />color=&#8220;blue&#8221;,&nbsp;<br />thickness=2,&nbsp;<br />npoints=4;&nbsp;<br />{x=0, y=0},&nbsp;<br />{x=-10, y=0},&nbsp;<br />{x=-5, y=4},&nbsp;<br />{x=0, y=4}&nbsp;<br />}</p><p>-- Print the color&nbsp;<br />print(myPolygon[&#8220;color&#8221;])</p><p>-- Print it again using dot&nbsp;<br />-- notation&nbsp;<br />print(myPolygon.color)</p><p>-- The points are accessible&nbsp;<br />-- in myPolygon[1] to myPolygon[4]</p><p>-- Print the second point&#8217;s x&nbsp;<br />-- coordinate&nbsp;<br />print(myPolygon[2].x)</p><p><strong>程序说明</strong></p><p>&nbsp; &nbsp; 首先建立一个table, 与上一例不同的是，在table的constructor里面有{x=0,y=0}, 这是什么意思呢？ 这其实就是一个小table, 定义在了大table之内, 小table的table名省略了.最后一行myPolygon[2].x，就是大table里面小table的访问方式.</p><div></div></p></div><img src ="http://www.cppblog.com/lauer3912/aggbug/195799.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2012-11-29 16:32 <a href="http://www.cppblog.com/lauer3912/archive/2012/11/29/195799.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>xcode4的环境变量，Build Settings参数，workspace及联编设置</title><link>http://www.cppblog.com/lauer3912/archive/2012/11/28/195770.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Wed, 28 Nov 2012 08:51:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2012/11/28/195770.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/195770.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2012/11/28/195770.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/195770.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/195770.html</trackback:ping><description><![CDATA[<h1> 			<a id="cb_post_title_url" href="http://www.cnblogs.com/xiaodao/archive/2012/03/28/2422091.html">xcode4的环境变量，Build Settings参数，workspace及联编设置</a> 		</h1> 		 		 			<div id="cnblogs_post_body"><p>一、xcode4中的环境变量</p> <div> <pre><span style="color: #ff0000;">$(BUILT_PRODUCTS_DIR)</span></pre> </div> <p>build成功后的，最终产品路径－－可以在Build Settings参数的Per-configuration Build Products Path项里设置</p> <div> <pre><span style="color: #ff0000;">$(TARGET_NAME)</span></pre> </div> <p>目标工程名称</p> <div> <pre><span style="color: #ff0000;">$(SRCROOT)</span></pre> </div> <p>工程文件（比如Nuno.xcodeproj）的路径&nbsp;</p> <div> <pre><span style="color: #ff0000;">$(CURRENT_PROJECT_VERSION)</span></pre> </div> <p>当前工程版本号</p> <p>&nbsp;</p> <p>其他：</p> <p>当编译静态库，设备选模拟器(iPhone 5.0 Simulator)，未设置任何Build Settings参数时，默认的基础路径：</p> <p>/Users/xxx/Library/Developer/Xcode/DerivedData/xxxWorkspace-caepeadwrerdcrftijaolkkagbjf</p> <p>下面用$()代替上面一长串东东</p> <p>$(SYMROOT) = $()/Build/Products</p> <p>$(BUILD_DIR) = $()/Build/Products</p> <p>$(BUILD_ROOT) = &nbsp;$()/Build/Products</p> <p>这三个变量中的$()不会随着Build Settings参数的设置而改变</p> <p>相反，以下可以通过设置而改变</p> <p>$(CONFIGURATION_BUILD_DIR) = $()/Build/Products/Debug-iphonesimulator</p> <p>$(BUILT_PRODUCTS_DIR) = $()/Build/Products/Debug-iphonesimulator</p> <p>$(CONFIGURATION_TEMP_DIR) = $()/Build/Intermediates/UtilLib.build/Debug-iphonesimulator</p> <p>$(TARGET_BUILD_DIR) = $()/Build/Products/Debug-iphonesimulator</p> <p>$(SDK_NAME) = iphonesimulator5.0</p> <p>$(PLATFORM_NAME) = iphonesimulator</p> <p>$(CONFIGURATION) = Debug</p> <p>$(TARGET_NAME) = UtilLib</p> <p>$(EXECUTABLE_NAME) = libUtilLib.a 可执行文件名</p> <p>${IPHONEOS_DEPLOYMENT_TARGET} 5.0</p> <p>$(ACTION) = build</p> <p>$(CURRENTCONFIG_SIMULATOR_DIR) 当前模拟器路径&nbsp;</p> <p>$(CURRENTCONFIG_DEVICE_DIR) 当前设备路径&nbsp;</p> <p>&nbsp;</p> <p>$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME =</p> <p>$()/Build/Products/Debug-iphonesimulator</p> <p>$(PROJECT_TEMP_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) = $()/Build/Intermediates/UtilLib.build/Debug-iphonesimulator</p> <p>&nbsp;</p> <p>自定义变量</p> <p>${CONFIGURATION}-iphoneos 表示：Debug-iphoneos</p> <p>${CONFIGURATION}-iphonesimulator&nbsp;表示：Debug-iphonesimulator</p> <p>$(CURRENTCONFIG_DEVICE_DIR) = ${SYMROOT}/${CONFIGURATION}-iphoneos</p> <p>$(CURRENTCONFIG_SIMULATOR_DIR) = ${SYMROOT}/${CONFIGURATION}-iphonesimulator</p> <p>自定义一个设备无关的路径（用来存放各种架构arm6/arm7/i386输出的产品）</p> <p>$(CREATING_UNIVERSAL_DIR) = ${SYMROOT}/${CONFIGURATION}-universal</p> <p>自定义变量代表的值</p> <p>$(CURRENTCONFIG_DEVICE_DIR) ＝ $()/Build/Products/Debug-iphoneos</p> <p>$(CURRENTCONFIG_SIMULATOR_DIR) =&nbsp;$()/Build/Products/Debug-iphonesimulator</p> <p>$(CREATING_UNIVERSAL_DIR) =&nbsp;$()/Build/Products/Debug-universal</p> <p>&nbsp;</p> <p>iphoneos5.0下的编译脚本：</p> <p>xcodebuild -project "UtilLib.xcodeproj"&nbsp;-configuration "Debug" -target "UtilLib" -sdk "<span style="color: #ff0000;">iphoneos5.0</span>" -arch "<span style="color: #ff0000;">armv6 armv7</span>" build RUN_CLANG_STATIC_ANALYZER=NO &nbsp;$(BUILD_DIR)="${BUILD_DIR}"&nbsp;BUILD_ROOT="${BUILD_ROOT}"</p> <p>&nbsp;</p> <p>iphonesimulator5.0下的编译脚本：</p> <p>xcodebuild -project "UtilLib.xcodeproj"&nbsp;-configuration "Debug" -target "UtilLib" -sdk "<span style="color: #ff0000;">iphonesimulator5.0</span>" -arch "<span style="color: #ff0000;">i386</span>" build RUN_CLANG_STATIC_ANALYZER=NO&nbsp;$(BUILD_DIR)="${BUILD_DIR}"&nbsp;&nbsp;BUILD_ROOT="${BUILD_ROOT}"</p> <p>加上下面一句表示输出到文件：</p> <p>&gt; "${BUILD_ROOT}.build_output"</p> <p>&nbsp;</p> <p><span style="color: #ff0000;">lipo脚本工具</span>：合并iPhone模拟器和真机的静态类库，生成通用库</p> <p>lipo -create -output&nbsp;"${CREATING_UNIVERSAL_DIR}/${EXECUTABLE_NAME}"  "${CURRENTCONFIG_DEVICE_DIR}/${EXECUTABLE_NAME}" &nbsp; &nbsp; &nbsp;  &nbsp;&nbsp;"${CURRENTCONFIG_SIMULATOR_DIR}/${EXECUTABLE_NAME}"</p> <p>意思是：把"${CURRENTCONFIG_DEVICE_DIR}目录下的.a文件，和${CURRENTCONFIG_SIMULATOR_DIR}目录下的.a文件合并，</p> <p>在${CREATING_UNIVERSAL_DIR}目录下，生成两个设备都通用的静态库,</p> <p>例如：lipo -create -output xy.a x.a y.a</p> <p>&nbsp;</p> <p>二、xcode4中build Settings常见参数解析</p> <p><span style="color: #ff0000;">1.Installation Directory</span>：安装路径</p> <p>静态库编译时，在Build Settings中Installation Directory设置&#8220;$(BUILT_PRODUCTS_DIR)&#8221;</p> <p>Skip Install设为YES</p> <p><span style="color: #808080;">Installation Directory默认为/usr/local/lib</span></p> <p><span style="color: #808080;">因为Build Location默认时，.a文件会放在很长（比如：/Users/xxx/Library/Developer/Xcode/DerivedData/xxxProgram</span></p> <p><span style="color: #808080;">dalrvzehhtesxdfqhxixzafvddwe/Build/Products/Debug-iPhoneos）的路径下，或是我们target指定的路径</span></p> <p><span style="color: #808080;">Skip Install如果是NO,可能会被安装到默认路径/usr/local/lib</span></p> <p><span style="color: #000000;"><span style="color: #ff0000;">2.Public Headers Folder Path</span>：对外公开头文件路径</span></p> <p>设为&#8220;include&#8221;（具体的头文件路径为：$(BUILT_PRODUCTS_DIR)/include/xx.h）</p> <p>在最终文件.a同级目录下生成一个include目录</p> <p><span style="color: #808080;">默认：/usr/local/include</span></p> <p><span style="color: #808080;">Public Headers Folder Path这个路径就是使用这lib的某工程需要依赖的外部头文件.导入这路径后，#include/import "xx.h"才能看到</span></p> <p><span style="color: #000000;"><span style="color: #ff0000;">3.User Header Search Paths</span>：依赖的外部头文件搜索路径</span></p> <p><span style="color: #000000;">设置为&#8220;$(BUILT_PRODUCTS_DIR)/include&#8221;</span></p> <p><span style="color: #808080;">和2中路径对应</span></p> <p><span data-mce-=""><span data-mce-=""><span style="color: #ff0000;">4.Per-configuration Build Products Path</span><span data-mce-="">：最终文件路径</span></span></span></p> <p>比如设为&#8220;../app&#8221;，就会在工程文件.xcodeproj上一层目录下的app目录里，创建最终文件</p> <p><span data-mce-="">默认为$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)</span>&nbsp;</p> <p><span data-mce-="">等于$(BUILT_PRODUCTS_DIR)</span></p> <p><span style="color: #ff0000;">5.Per-configuration Intermediate Build Files Path</span>：临时中间文件路径</p> <p>默认为：$(PROJECT_TEMP_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)</p> <p><span style="color: #000000;"><span style="color: #ff0000;">6.Code Signing Identity</span>：真机调试的证书选择</span></p> <p><span style="color: #000000;">选一个和Bundle identifier相对应的证书</span></p> <p><span style="color: #ff0000;">Library Search Paths</span>：库搜索路径</p> <p><span style="color: #ff0000;">Architectures</span>：架构，设为 armv6 或 armv7</p> <p><span style="color: #ff0000;">Valid&nbsp;</span><span style="color: #ff0000;">Architectures：应用框架，可以设为&nbsp;armv6、</span>&nbsp;armv7 或i386</p> <p><span style="color: #ff0000;">Product Name</span>:工程文件名，默认为$(TARGET_NAME)</p> <p><span style="color: #000000;"><span style="color: #ff0000;">Info.plist File：</span>info文件路径</span></p> <p><span style="color: #ff0000;">Build Variants</span>：默认为normal</p> <p><span style="color: #000000;"><span style="color: #ff0000;">Other Linker Flags</span>：其他链接标签</span></p> <p>设为&#8220;-ObjC&#8221;</p> <p><span style="color: #808080;">当导入的静态库使用了类别，需要设为-ObjC</span></p> <p><span style="color: #808080;"><span style="color: #ff0000;">iOS Deployment Target<span style="color: #000000;"><span data-mce-=""><span data-mce-="">：ios</span>部署对象</span></span></span></span></p> <p><span style="color: #808080;"><span style="color: #ff0000;"><span style="color: #000000;"><span data-mce-="">比如可以选择设为，ios3到ios5的一种版本</span></span></span></span></p> <p><span style="color: #000000;"><span style="color: #ff0000;">Prefix Header</span>：预编头文件（</span>比如：UtilLib/UtilLib-Prefix.pch）</p> <p><span style="color: #ff0000;">Precompile&nbsp;Prefix Header</span>：设为&#8220;Yes&#8221;，表示允许加入预编译头</p> <p>&nbsp;</p> <p>三、workspace（工作区）</p> <p>作用：管理多个工程（project），多工程联编</p> <p>&nbsp;</p> <p>四、workspace多工程联编设置</p> <p>一、</p> <p>1.新建一个静态库工程，比如UtilLib，并生成UtilLib.h和UtilLib.m文件</p> <p>2.选中需要公开的头文件，</p> <p><img src="http://pic002.cnblogs.com/images/2012/373740/2012032821514514.png" alt="" /></p> <p>把右侧栏的Target Membership中设置为public</p> <p><img src="http://pic002.cnblogs.com/images/2012/373740/2012032821520658.png" alt="" /></p> <p>或则，选中工程目录target的Build Phases标签的copy headers项，在public中添加要公开的头文件</p> <p><img src="http://pic002.cnblogs.com/images/2012/373740/2012032822023943.png" alt="" /></p> <p>3.<span data-mce-="">Architectures</span>设为：armv6 armv7</p> <p>4.<span data-mce-="">Valid&nbsp;</span><span data-mce-="">Architectures设为</span>：armv6 armv7 i386</p> <p>5.Build Products Path设为：$(SRCROOT)/../build</p> <p>6.<span data-mce-="">Per-configuration Build Products Path设为：</span></p> <p><span data-mce-="">$(SRCROOT)/../build/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)</span></p> <p><span data-mce-="">7.Per-configuration Intermediate Build Files Path设为：</span></p> <p><span data-mce-="">$(SRCROOT)/../build/$(TARGET_NAME).build/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)</span></p> <p>8.设置安装路径：Installation Directory项</p> <p><img src="http://pic002.cnblogs.com/images/2012/373740/2012032822444226.png" alt="" /></p> <p>9.设置对外公开的头文件路径：Public Headers Folder Path项</p> <p><img src="http://pic002.cnblogs.com/images/2012/373740/2012032823052996.png" alt="" /></p> <p><span data-mce-=""><br /></span></p> <p><span style="color: #ff0000;">10.为静态库添加依赖的shell脚本</span></p> <p>选中工程目录target的Build Phases标签，点击由下角的Add Build Phase按钮</p> <p><img src="http://pic002.cnblogs.com/images/2012/373740/2012033001445848.png" alt="" /></p> <p>在弹出的菜单里选择Add run script项，然后页面中会多出一个Run Script项</p> <p><img src="http://pic002.cnblogs.com/images/2012/373740/2012033001465346.png" alt="" /></p> <p>在黑框里填写"$SRCROOT/mergeArmSymbols.sh"</p> <p><img src="http://pic002.cnblogs.com/images/2012/373740/2012033001492012.png" alt="" /></p> <p>建立对此脚本的依赖（编译静态库的后会运行此脚本）</p> <p>如果编译时设备选的是iphone simulator：</p> <p>则此脚本会在对应iphone device的产品目录Debug-iphoneos中，生成对device有用的.a静态库，</p> <p>相反，如果设备选的是iphone&nbsp;device：</p> <p>则此脚本会在对应iphone simulator的产品目录Debug-iphoneos中，生成对simulator有用的.a静态库</p> <p>最后，此脚本调用<span style="color: #ff0000;">lipo工具，</span>把本工程生成静态库与此脚本生成的静态库合并，生成simulator和device都通用的.a文件</p> <p>&nbsp;</p> <p>11.<span style="color: #ff0000;">具体bash shell脚本如下</span>：</p> <div><img id="code_img_closed_27ad3a54-4ce7-402f-a5c8-c7548fe825c8" src="http://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif" alt="" />mergeArmSymbols.sh  </div> <p>下载右边的图片<img src="http://pic002.cnblogs.com/images/2012/373740/2012040300261146.jpg" alt="" />，然后把后缀改为.sh（其实就是上面的脚本，因为博客园只能上传图片)</p> <p>静态库编译后的目录结构如下：</p> <p><img src="http://pic002.cnblogs.com/images/2012/373740/2012040300174762.png" alt="" /></p> <p><img src="http://pic002.cnblogs.com/images/2012/373740/2012040300180494.png" alt="" /></p> <p>&nbsp;</p> <p>二、&nbsp;</p> <p>1.新建主工程，比如Nuno，添加对静态库的依赖</p> <p>点击工程，在Build Phases标签的<span>Link Binary With Libraries项中点击加号添加UtilLib.a库</span></p> <p><img src="http://pic002.cnblogs.com/images/2012/373740/2012032823190886.png" alt="" /></p> <p><img src="http://pic002.cnblogs.com/images/2012/373740/2012032823194638.png" alt="" /></p> <p><img src="http://pic002.cnblogs.com/images/2012/373740/2012032823200838.png" alt="" /></p> <p>选中上面的红色项，在右边栏的Location选Relative to Project，把值设为../libs/libUtilLib.a</p> <p>2.设置主工程依赖的外部头文件路径：User Header Search Paths项</p> <p>$(SRCROOT)/../include</p> <p>3.设置Header Search Paths为：$(SRCROOT)/../include</p> <p>4.设置Library Search Paths为：$(SRCROOT)/../libs</p> <p>编译运行即可实现联编&nbsp;</p> <p>&nbsp;</p> <p>(备注：选择模拟器iphone 5.0&nbsp;simulator，编译静态库的时，最终文件会在Debug-iphonesimulator，就算成功.a文件还是红色，</p> <p>这是可能是xcode的bug，不会自动切换路径</p> <p>因为$(BUILT_PRODUCTS_DIR)所指的位置，是build/Debug-iphonesos,不是包含最终.a文件的Debug-iphonesimulator；</p> <p>选择ios Device，编译成的最终文件才在build/Debug-iphonesos下，.a文件变成非红色</p> <p>所有得用mergeArmSymbols.sh脚本来解决）</p> <p><br /></p></div><img src ="http://www.cppblog.com/lauer3912/aggbug/195770.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2012-11-28 16:51 <a href="http://www.cppblog.com/lauer3912/archive/2012/11/28/195770.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>默认标签TODO,XXX,FIXME和自定义标签的使用</title><link>http://www.cppblog.com/lauer3912/archive/2012/11/28/195761.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Wed, 28 Nov 2012 04:21:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2012/11/28/195761.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/195761.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2012/11/28/195761.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/195761.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/195761.html</trackback:ping><description><![CDATA[1.&nbsp;&nbsp;&nbsp; // TODO &#8212;&#8212;
表示尚未完成的待办事项。<br />
2.&nbsp;&nbsp;&nbsp; // XXX &#8212;&#8212;
表示被注释的代码虽然实现了功能，但是实现方案有待商榷，希望将来能改进。<br />
3.&nbsp;&nbsp;&nbsp; // FIXME
&#8212;&#8212; 表示被注释的代码需要被修正。<img src ="http://www.cppblog.com/lauer3912/aggbug/195761.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2012-11-28 12:21 <a href="http://www.cppblog.com/lauer3912/archive/2012/11/28/195761.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>UIBarButtonSystemItem的样式图片(转)</title><link>http://www.cppblog.com/lauer3912/archive/2012/11/26/195698.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Mon, 26 Nov 2012 06:16:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2012/11/26/195698.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/195698.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2012/11/26/195698.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/195698.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/195698.html</trackback:ping><description><![CDATA[<h2>
			<a id="cb_post_title_url" href="http://www.cnblogs.com/KidReborn/archive/2010/11/20/1882346.html">UIBarButtonSystemItem的样式图片</a>
		</h2>
		<div id="cnblogs_post_body"><p>&nbsp;</p>
<div class="cnblogs_Highlighter">
<pre class="brush:objc">typedef enum {
    UIBarButtonSystemItemDone,
    UIBarButtonSystemItemCancel,
    UIBarButtonSystemItemEdit,  
    UIBarButtonSystemItemSave,  
    UIBarButtonSystemItemAdd,
    UIBarButtonSystemItemFlexibleSpace,
    UIBarButtonSystemItemFixedSpace,
    UIBarButtonSystemItemCompose,
    UIBarButtonSystemItemReply,
    UIBarButtonSystemItemAction,
    UIBarButtonSystemItemOrganize,
    UIBarButtonSystemItemBookmarks,
    UIBarButtonSystemItemSearch,
    UIBarButtonSystemItemRefresh,
    UIBarButtonSystemItemStop,
    UIBarButtonSystemItemCamera,
    UIBarButtonSystemItemTrash,
    UIBarButtonSystemItemPlay,
    UIBarButtonSystemItemPause,
    UIBarButtonSystemItemRewind,
    UIBarButtonSystemItemFastForward,
#if __IPHONE_3_0 &lt;= __IPHONE_OS_VERSION_MAX_ALLOWED
    UIBarButtonSystemItemUndo,
    UIBarButtonSystemItemRedo,
#endif
#if __IPHONE_4_0 &lt;= __IPHONE_OS_VERSION_MAX_ALLOWED
    UIBarButtonSystemItemPageCurl,
#endif
} UIBarButtonSystemItem;
</pre>
</div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>图片如下:</p>
<p><img src="http://pic002.cnblogs.com/images/2010/144660/2010112005564010.png" alt="" /><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; white-space: pre;">UIBarButtonSystemItemAdd</span></p>
<p><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12pt;"><span style="font-size: 13px; line-height: 19px; white-space: pre;"><img src="http://pic002.cnblogs.com/images/2010/144660/2010112005571910.png" alt="" />UIBarButtonSystemItemCompose</span></span></p>
<p><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12pt;"><span style="font-size: 13px; line-height: 19px; white-space: pre;"><img src="http://pic002.cnblogs.com/images/2010/144660/2010112005575462.png" alt="" />UIBarButtonSystemItemReply</span></span></p>
<p><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12pt;"><span style="font-size: 13px; line-height: 19px; white-space: pre;"><img src="http://pic002.cnblogs.com/images/2010/144660/2010112005592695.png" alt="" />UIBarButtonSystemItemAction</span></span></p>
<p><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12pt;"><span style="font-size: 13px; line-height: 19px; white-space: pre;"><img src="http://pic002.cnblogs.com/images/2010/144660/2010112006002674.png" alt="" /><span style="font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px; white-space: normal;">UIBarButtonSystemItemOrganize</span></span></span></p>
<p><img src="http://pic002.cnblogs.com/images/2010/144660/2010112006013193.png" alt="" />UIBarButtonSystemItemBookmarks</p>
<p><img src="http://pic002.cnblogs.com/images/2010/144660/2010112006025240.png" alt="" />UIBarButtonSystemItemSearch</p>
<p><img src="http://pic002.cnblogs.com/images/2010/144660/2010112006034047.png" alt="" />UIBarButtonSystemItemRefresh</p>
<p><img src="http://pic002.cnblogs.com/images/2010/144660/2010112006045045.png" alt="" />UIBarButtonSystemItemStop</p>
<p><img src="http://pic002.cnblogs.com/images/2010/144660/2010112006055147.png" alt="" />UIBarButtonSystemItemCamera</p>
<p><img src="http://pic002.cnblogs.com/images/2010/144660/2010112006065720.png" alt="" />UIBarButtonSystemItemTrash</p>
<p><img src="http://pic002.cnblogs.com/images/2010/144660/2010112006082576.png" alt="" />UIBarButtonSystemItemPlay</p>
<p><img src="http://pic002.cnblogs.com/images/2010/144660/2010112006092415.png" alt="" />UIBarButtonSystemItemPause</p>
<p><img src="http://pic002.cnblogs.com/images/2010/144660/2010112006101060.png" alt="" />UIBarButtonSystemItemRewind</p>
<p><img src="http://pic002.cnblogs.com/images/2010/144660/2010112006105911.png" alt="" />UIBarButtonSystemItemFastForward</p>
<p><img src="http://pic002.cnblogs.com/images/2010/144660/2010112006121056.png" alt="" />UIBarButtonSystemItemUndo</p>
<p><img src="http://pic002.cnblogs.com/images/2010/144660/2010112006130059.png" alt="" />UIBarButtonSystemItemRedo</p></div><div id="MySignature">天下风云出我辈, 一入江湖岁月催. 皇图霸业笑谈中, 不胜人生一场醉.
</div><img src ="http://www.cppblog.com/lauer3912/aggbug/195698.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2012-11-26 14:16 <a href="http://www.cppblog.com/lauer3912/archive/2012/11/26/195698.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>由init、loadView、viewDidLoad、viewDidUnload、dealloc的关系说起 (转载)</title><link>http://www.cppblog.com/lauer3912/archive/2012/11/23/195588.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Fri, 23 Nov 2012 02:41:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2012/11/23/195588.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/195588.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2012/11/23/195588.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/195588.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/195588.html</trackback:ping><description><![CDATA[原文：http://blog.csdn.net/weiqubo/article/details/8152326<br /><br />
    <h3>
        <span class="link_title"><a href="http://blog.csdn.net/weiqubo/article/details/8152326">
        由init、loadView、viewDidLoad、viewDidUnload、dealloc的关系说起
        </a></span>
    </h3>


        
    <div class="article_manage">
        <span class="link_categories">
        分类：
            <a href="http://blog.csdn.net/weiqubo/article/category/1087781">iOS</a> 
        </span>
    <span class="link_postdate">2012-11-06 12:20</span>
    <span class="link_view" title="阅读次数">273人阅读</span>
    <span class="link_comments" title="评论次数"><a href="http://blog.csdn.net/weiqubo/article/details/8152326#comments">评论</a>(0)</span>
    <span class="link_collect"><a title="收藏">收藏</a></span>
    <span class="link_report"><a href="http://blog.csdn.net/weiqubo/article/details/8152326#report" title="举报">举报</a></span>
    
</div>


    


<p style="margin:10px auto; font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px; line-height:23px">
<span style="line-height:19px">对于<span id="rlt_1">iphone开发</span>人员来说，内存管理是极为重要的技巧，哪怕程序的功能再强大，<span id="rlt_8">设计</span>再漂亮，如果内存控制不好，也难逃程序莫名退出的噩运，这与网页<span id="rlt_2">开发</span>是完全不同的。<br />
<br />
内存控制里面有很多门道，在这里分析一下 viewDidUnload 和 dealloc 的区别，关于这两者的区别的文章很多，但是大都是摘抄和翻译官方文档，有的也只是简单的说两句，并没有详细说出两者具体的区别。<br />
<br />
在了解两者之间的区别，首先要知道&nbsp;<span id="rlt_7">view</span>&nbsp;的生命周期，google 里面有很多文章，可以先去搜一下，这里就不详解了。<br />
<br />
顾名思义 &#8200;<strong>viewDidUnload</strong>&nbsp;就是当 view 被卸载以后执行的语句，它与 viewDidLoad 是相互呼应的。大家都知道官方的解释是执行类似</span></p>
<p style="margin:10px auto; font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px; line-height:23px">
&nbsp;</p>
<p style="margin:10px auto; font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px; line-height:23px">
<span style="line-height:19px"><code class="objc keyword">self</code><code class="objc plain">.myOutlet =&nbsp;</code><code class="objc keyword">nil</code><code class="objc plain">;</code></span></p>
<p style="margin:10px auto; font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px; line-height:23px">
&nbsp;</p>
<p style="margin:10px auto; font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px; line-height:23px">
的命令，但是为什么这么干，什么时候调用这个方法呢？<br />
<br />
<span style="line-height:19px">这个方法是不能手动调用的，它实际上是当<span id="rlt_4">应用</span>程序接收到手机内存警告的时候自动调用的方法，目的就是清空内存除当前&nbsp;viewController&nbsp;以外所有已经加载过的&nbsp;viewController 里面的暂时不再<span id="rlt_6">使用</span>的一些控件或数据，以避免应用程序应消耗内存过多被强制关闭。记住，是<strong><span style="color:#ff0000">除当前正在展示的
 view&nbsp;所属&nbsp;viewController 以外所有已经在内存里面的 viewController 执行&nbsp;viewDidUnload 方法</span></strong>，
而不是当前 viewController&nbsp;执行 viewDidUnload，当然，这些 viewController 不会被 
dealloc。所以在 viewDidUnload 里面一般都是释放 IBOutlet 变量和在 
viewDidLoad、viewWillAppear、viewDidAppear 等方法能够重建的数据。而由其他页面传递过来的数据或者无法经过
 viewDidLoad、viewWillAppear、viewDidAppear 等方法重建的数据则不能释放，举例子说如果在 
navigationController 由上一个页面传递过来的一张<span id="rlt_5">图片</span>，在 viewDidUnload 里被释放的话，则当 view 再次加载的时候就无法恢复了。</span><br />
<br />
<span style="line-height:19px">那为什么要写成 self.myOutlet = nil; ，实际上这个语法是执行了
 property 里的setter 方法，而不是一个简单的变量赋值，它干了两件事：1、老数据 
release&nbsp;掉，2、新数据（nil）retain（当 property 设置为 retain 的情况下），当然对 nil retain 
是无意义的。如果写成 myOutlet = nil，那就是简单的把 myOutlet 指向 nil，这样内存就泄漏了，因为老数据没有
 release。而如果仅仅写成&nbsp;[myOutlet release] 也会有<span id="rlt_3">问题</span>，因为当 view&nbsp;被 dealloc 的时候会 再次 release，程序就出错了，而对 nil release 是没有问题的。<br />
&nbsp;<br />
<strong>dealloc</strong>&nbsp;是当前 viewController 被释放的时候，清空所有当前 viewController
 里面的实体和数据来释放内存，该方法也是自动调用的，无需手动执行。举例说明当 modalView 被 
dismissModalViewControllerAnimated 或者 navigationController 
回到上一页的时候，这个方法就会被自动调用。因为这个页面已经不再使用了，所以可以把所有实体和数据都释放（release）掉。<br />
<br />
其实两者最大的区别就是： viewDidUnload 是内存除当前以外所有 viewController 同时执行，而 dealloc 只是当前 viewController 执行。这个是网上的材料没有说明的。<br />
<br />
个人拙见，不对之处还请提正！<br />
<br />
PS: 很多朋友都说无法调试 viewDidUnload，其实是可以的。方法是在 iOS 模拟器的菜单里选 <span style="color:#ff0000">
硬件-&gt;模拟内存警告</span>，这个时候就可以看到 viewDidUnload 里面 NSLog 的东西了，可以试试在打开过的 viewController 里都 NSLog 一下看看效果。而 dealloc 里面可以直接 NSLog。</span></p>
<p style="margin:10px auto; font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px; line-height:23px">
<span style="line-height:19px"><br />
</span></p>
<p style="margin:10px auto; font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px; line-height:23px">
<span style="line-height:19px"><br />
</span></p>
<p style="margin:10px auto; font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:13px; line-height:23px">
<span style="line-height:19px"></span></p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; color:#454545; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">
由init、loadView、viewDidLoad、viewDidUnload、dealloc的关系说起</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; color:#454545; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">
<strong>init方法</strong></p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; color:#454545; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">
在init方法中实例化必要的对象（遵从LazyLoad思想）</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; color:#454545; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">
init方法中初始化ViewController本身</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; color:#454545; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">
<strong>&nbsp;loadView方法</strong></p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; color:#454545; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">
当view需要被展示而它却是nil时，viewController会调用该方法。不要直接调用该方法。</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">
<span style="color:#ff0000">如果手工维护views，必须重载重写该方法</span></p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">
<span style="color:#ff0000">如果使用IB维护views，必须不能重载重写该方法</span></p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; color:#454545; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">
loadView和IB构建view</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; color:#454545; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">
你在控制器中实现了loadView方法，那么你可能会在应用运行的某个时候被内存管理控制调用。 如果设备内存不足的时候， view 
控制器会收到didReceiveMemoryWarning的消息。 默认的实现是检查当前控制器的view是否在使用。 
如果它的view不在当前正在使用的view hierarchy里面，且你的控制器实现了loadView方法，那么这个view将被release,
 loadView方法将被再次调用来创建一个新的view。</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; color:#454545; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">
<strong></strong>&nbsp;</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; color:#454545; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">
<strong>viewDidLoad方法</strong></p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">
<strong><span style="color:#ff0000">viewDidLoad 此方法只有当view从nib文件初始化的时候才被调用。</span><br />
</strong></p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; color:#454545; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">
重载重写该方法以进一步定制view</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; color:#454545; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">
在iPhone OS 3.0及之后的版本中，还应该重载重写viewDidUnload来释放对view的任何索引</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; color:#454545; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">
viewDidLoad后调用数据Model</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; color:#454545; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">
</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; color:#454545; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">
<strong>viewDidUnload方法</strong></p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">
<span style="color:#454545">当系统内存吃紧的时候会调用该方法</span><span style="color:#ff0000">（注：viewController没有被dealloc）</span></p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">
<span style="color:#454545">内存吃紧时，</span><span style="color:#ff0000">在iPhone OS 3.0之前didReceiveMemoryWarning是释放无用内存的唯一方式，但是OS 3.0及以后viewDidUnload方法是更好的方式</span></p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; color:#454545; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">
在该方法中将所有IBOutlet（无论是property还是实例变量）置为nil（系统release view时已经将其release掉了）</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; color:#454545; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">
在该方法中释放其他与view有关的对象、其他在运行时创建（但非系统必须）的对象、在viewDidLoad中被创建的对象、缓存数据等 
release对象后，将对象置为nil（IBOutlet只需要将其置为nil，系统release view时已经将其release掉了）</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; color:#454545; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">
一般认为viewDidUnload是viewDidLoad的镜像，因为当view被重新请求时，viewDidLoad还会重新被执行</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; color:#454545; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">
viewDidUnload中被release的对象必须是很容易被重新创建的对象（比如在viewDidLoad或其他方法中创建的对象），不要release用户数据或其他很难被重新创建的对象</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; color:#454545; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">
<strong>dealloc方法</strong></p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">
<span style="color:#ff0000">viewDidUnload和dealloc方法没有关联</span><span style="color:#454545">，dealloc还是继续做它该做的事情</span></p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; color:#454545; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">
</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; color:#454545; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">
看到以下的代码</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; color:#454545; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">
- (void)viewDidUnload {</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; color:#454545; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">
self.detailViewController = nil;&nbsp;</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; color:#454545; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">
self.languageNames = nil;&nbsp;</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; color:#454545; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">
self.languageCodes = nil;</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; color:#454545; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">
}</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; color:#454545; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">
- (void)dealloc {</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; color:#454545; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">
[detailViewController release];</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; color:#454545; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">
&nbsp;[languageNames release];&nbsp;</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; color:#454545; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">
[languageCodes release];&nbsp;</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; color:#454545; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">
[super dealloc];</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; color:#454545; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">
}</p>
<br style="color:#454545; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px" />
<span style="color:#454545; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">如果是先调用viewDidUnload后再调用dealloc, 那么languageNames都已经是nil了，再掉release有什么意义呢？</span><br style="color:#454545; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px" />
<span style="color:#454545; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">原
因似乎是， 对一个viewcontroller来说，它的数据的初始化在init中，而它管理的view采用了lazy 
load的方式，也就是有需要的时候才会载入， 所以跟view相关的数据可以在viewDidLoad（也就是在view被载入的时候）进行初始化。</span><span style="font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px"><span style="color:#ff0000">当内存紧张的时候，
 ios会销毁点一些view， 通过调用viewDidUnload （里面一般也只是把跟view相关的数据设为nil）, 但这个时候viewcontroller本身还在， 所以它的dealloc不会被调用</span></span><span style="color:#454545; font-family:tahoma,Helvetica,arial; font-size:14px; line-height:21px">，除非是到了viewcontroller也被销毁的时候</span><img src ="http://www.cppblog.com/lauer3912/aggbug/195588.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2012-11-23 10:41 <a href="http://www.cppblog.com/lauer3912/archive/2012/11/23/195588.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>iOS的多核编程和内存管理（转）</title><link>http://www.cppblog.com/lauer3912/archive/2012/11/16/195252.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Thu, 15 Nov 2012 22:46:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2012/11/16/195252.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/195252.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2012/11/16/195252.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/195252.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/195252.html</trackback:ping><description><![CDATA[<p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">隔上一次写iPad app开发文章已经是10个月，那篇iPad app开发概述还不错，曾经成为了google关键字&#8220;iPad app 开发&#8221;搜索的第一位，可能是大牛们都太忙于赚app store的钱了，留下我这个小虾来写文章。这次的文章集中与iOS的多核编程和内存管理，为什么？因为iPad 2已经是双核CPU了！虽然iPad 1的应用已经不慢了，但大家完全可以使用苹果的多核编程框架来写出更加responsive的应用。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><strong>多核运算</strong></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">在iOS中concurrency编程的框架就是GCD(Grand Central Dispatch)， GCD的使用非常简单。它把任务分派到不同的queue队列来处理。开发者把任务代码装到一个个block里面，操作系统把这些任务代码分派到不同的资源里去处理，一个简单的例子来说，为什么初学者写tableview的时候，滑动列表时总会很卡，因为很多初学者把图片装载放到main thread主线程去执行，例如我们要滑动畅顺的话，iOS最快可以1秒内刷新60次，如何你的一个cell的文字和图片装载超过1/60秒的话，自然就会卡。所以一般我们会把图片装载这些需要多点时间的移出main thread来处理，对于用GCD来说，就是把图片载入放到另外一个queue队列中来异步执行，当资源准备好了后，放回到main thread中显示出来。main thread在GCD中就是main queue。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">创建一个新queue队列的代码：</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #ffffff; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.1875px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">C代码&nbsp;<embed wmode="transparent" src="http://anxonli.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" width="14" height="15" flashvars="clipboard=dispatch_queue_t%20network_queue%3B%0A%0Anetwork_queue%20%3D%20dispatch_queue_create(%22com.myapp.network%22%2C%20nill)%3B" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">&nbsp;<a href="" title="收藏这段代码" style="color: #108ac6;"><img src="http://anxonli.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">dispatch_queue_t&nbsp;network_queue;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">network_queue&nbsp;=&nbsp;dispatch_queue_create("com.myapp.network",&nbsp;nill);&nbsp;&nbsp;</li></ol></div><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">例如，我们图片读取放到network_queue来进行异步执行</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #ffffff; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.1875px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">C代码&nbsp;<embed wmode="transparent" src="http://anxonli.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" width="14" height="15" flashvars="clipboard=dispatch_async(network_queue%2C%20%5E%7B%20%20%0A%20%20%20%20UIImage%20*cellImage%20%3D%20%5Bself%20loadMyImageFromNetwork%3Aimage_url%5D%3B%20%20%0A%20%20%20%20%2F%2F%20%E5%B0%86%E5%9B%BE%E7%89%87cache%E5%88%B0%E6%9C%AC%E5%9C%B0%20%20%0A%20%20%20%20%5Bself%20cacheImage%3AcellImage%5D%3B%20%20%0A%20%20%0A%20%20%20%20.....%20%20%0A%20%20%20%20%20%20%0A%7D%20)%3B" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">&nbsp;<a href="" title="收藏这段代码" style="color: #108ac6;"><img src="http://anxonli.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">dispatch_async(network_queue,&nbsp;^{&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;UIImage&nbsp;*cellImage&nbsp;=&nbsp;[self&nbsp;loadMyImageFromNetwork:image_url];&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="width: auto; border-width: 0px;">//&nbsp;将图片cache到本地&nbsp;&nbsp;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;[self&nbsp;cacheImage:cellImage];&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;.....&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">}&nbsp;);&nbsp;&nbsp;</li></ol></div>&nbsp;<p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">dispatch_async的意思就是将任务进行异步并行处理，不一定需要一个任务处理完后才能处理下一个。以上代码loadMyImageFromNetwork的意思就是从网络中读取图片，这个任务交给network_queue来处理。这样读取图片的时间过长也不会阻塞主线程界面的处理。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">当我们处理完图片后，应该更新界面，从queue的概念去设计，就是要将更新界面的代码放到main queue中去，因为iOS里面永远是主线程来刷新重画UI。所以代码应该为，</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #ffffff; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.1875px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">C代码&nbsp;<embed wmode="transparent" src="http://anxonli.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" width="14" height="15" flashvars="clipboard=dispatch_async(network_queue%2C%20%5E%7B%20%20%0A%20%09UIImage%20*cellImage%20%3D%20%5Bself%20loadMyImageFromNetwork%3Aimage_url%5D%3B%20%20%0A%20%20%20%20%2F%2F%20%E5%B0%86%E5%9B%BE%E7%89%87cache%E5%88%B0%E6%9C%AC%E5%9C%B0%20%20%0A%20%20%20%20%5Bself%20cacheImage%3AcellImage%5D%3B%20%20%0A%20%20%0A%20%20%20%2F%2F%20%E5%9B%9E%E5%88%B0%E4%B8%BB%E7%BA%BF%E7%A8%8B%20%20%0A%20%20%20dispatch_async(dispatch_get_main_queue()%2C%20%5E%7B%20%20%0A%20%20%20%20%20%20%2F%2F%20%E6%98%BE%E7%A4%BA%E5%9B%BE%E7%89%87%E5%88%B0%E7%95%8C%E9%9D%A2%20%20%0A%20%20%20%20%20%20%5Bself%20displayImageToTableView%3AcellImage%5D%3B%20%20%0A%20%20%20%7D%5D%3B%20%20%0A%20%20%20%20%20%20%0A%7D%20)%3B" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">&nbsp;<a href="" title="收藏这段代码" style="color: #108ac6;"><img src="http://anxonli.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">dispatch_async(network_queue,&nbsp;^{&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;UIImage&nbsp;*cellImage&nbsp;=&nbsp;[self&nbsp;loadMyImageFromNetwork:image_url];&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="width: auto; border-width: 0px;">//&nbsp;将图片cache到本地&nbsp;&nbsp;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;[self&nbsp;cacheImage:cellImage];&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;<span style="width: auto; border-width: 0px;">//&nbsp;回到主线程&nbsp;&nbsp;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;dispatch_async(dispatch_get_main_queue(),&nbsp;^{&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="width: auto; border-width: 0px;">//&nbsp;显示图片到界面&nbsp;&nbsp;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[self&nbsp;displayImageToTableView:cellImage];&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;}];&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">}&nbsp;);&nbsp;&nbsp;</li></ol></div>&nbsp;<p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">dispatch_get_main_queue() 函数就是返回主线程，^{} 封装的就是任务代码，这样嵌套方式就可以从一个队列queue，跳到另一个queue，就是这么简单。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">我们一般可以把networking有关的代码放到一个queue，把图片resize的代码放到另外一个queue，处理完后更新界面，只需要嵌套跳回到 main queue。这样加上几行代码，你的程序就可以利用到系统多核资源，把具体的调度工作交给了操作系统自己来分配。有了这样的代码，不管你的硬件是单核，双核还是iMac的4核，甚至8核，都可以非常好地并行处理。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><strong>内存管理</strong></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">我一直惊叹iOS和Objective-C内存处理能力，例如iPad版本的iWork，Pages应用就是一个内存处理技术应用的鬼斧神工之作。想想256M内存的iPad，可以带来如此的华丽的界面同时获得如此流畅的用户体验，真是不简单。原因就是iOS一直提倡开发者在有限硬件资源内写出最优化的代码，使用CPU最少，占用内存最小。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">（以下代码适用于iOS SDK 4.1, 由于新SDK 4.2对内存使用有新改动，所以可能有不同。。。）</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">1. 尽量少的UIView层</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">通常我们喜欢把很多控件层（UILabel，UIButton，UIView等）一起放到一个大的UIView容器来显示我们的内容，这个方法一般是可以的，但是如果要经常重新刷新内容的大区域界面，多数发生在iPad的应用中，这个方法会带来过多的内存使用和动画的延迟（比较卡），例如，scrollview的动画比较卡，又或者，经常收到内存警告。其中一个重要原因是每个控件，特别是透明底的，会多次重新绘制（drawRect）过多。其解决办法是，尽量将几个控件合并到一个层上来显示，这样系统会减少系统调用drawRect，从而带来性能上的提升。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">很简单的一个例子，就是iNotes提供手写功能，用户可以在iPad屏幕上写出不同的笔画，开始的设计是，用户每写一划，iNotes就会生成一个新的透明底UIView来保持这个笔画，用户写了10笔，系统就生产了10个UIView，每个view的大小都是整个屏幕的，以便用户的undo操作。这个方案带来严重的内存问题，因为系统将每个层都保持一个bitmap图，一个像素需要4bit来算，一个层的大小就是 4x1024x768 ~ 3M, 10个层就是 10x3M = 30M，很明显，iPad很快爆出内存警告。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">这个例子最后的方案是，所有笔画都画在同一个层，iNotes可以保存笔画的点进行undo操作。这样的方案就是无论用户画多少笔画，界面重画需要的资源都是一样的。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">2. 显示最佳尺寸的图片</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">很多程序员比较懒，网络上拿下来的图片，直接就用UIImageView将其显示给用户，这样的后果就是，程序需要一直保存着大尺寸的图片到内存。解决办法应该是先将图片缩小到需要显示的尺寸，释放大尺寸图片的内存，然后再显示到界面给用户。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">3. 尽量使用图片pattern，而不是一张大的图片</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">例如，很多界面设计者喜欢在界面上放一个大底图，但这个底图是老是占用着内存的，最佳方案是，设计出一个小的pattern图，然后用这个方案显示成底图。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #ffffff; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.1875px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">C代码&nbsp;<embed wmode="transparent" src="http://anxonli.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" width="14" height="15" flashvars="clipboard=UIImage%20*smallImage%20%3D%20%5B%5BUIImage%20alloc%5D%20initWithContentsOfFile%3Apath%5D%3B%0A%0AbackgroundView.backgroundColor%20%3D%20%5BUIColor%20colorWithPatternImage%3AsmallImage%5D%3B%0A%0A%5BsmallImage%20release%5D%3B" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">&nbsp;<a href="" title="收藏这段代码" style="color: #108ac6;"><img src="http://anxonli.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">UIImage&nbsp;*smallImage&nbsp;=&nbsp;[[UIImage&nbsp;alloc]&nbsp;initWithContentsOfFile:path];&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">backgroundView.backgroundColor&nbsp;=&nbsp;[UIColor&nbsp;colorWithPatternImage:smallImage];&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[smallImage&nbsp;release];&nbsp;&nbsp;</li></ol></div>&nbsp;<p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">4. 使用完资源后，立即释放</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">一般objective-c的习惯是，用完的资源要立即释放，因为明白什么时候用完某个资源的是程序员你自己。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">例如，我们要读较大的图片，把它缩小后，显示到界面去。当大图片使用完成后，应该立即释放。代码如下：</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"></p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #ffffff; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.1875px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">C代码&nbsp;<embed wmode="transparent" src="http://anxonli.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" width="14" height="15" flashvars="clipboard=UIImage%20*fullscreenImage%20%3D%20%5B%5BUIImage%20alloc%5D%20initWithContentOfFile%3Apath%5D%3B%0AUIImage%20*smallImage%20%3D%20%5Bself%20resizeImage%3AfullscreenImage%5D%3B%0A%0A%5BfullscreenImage%20release%5D%3B%0A%0AimageView.image%20%3D%20smallImage%3B%0A%0A......" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">&nbsp;<a href="" title="收藏这段代码" style="color: #108ac6;"><img src="http://anxonli.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">UIImage&nbsp;*fullscreenImage&nbsp;=&nbsp;[[UIImage&nbsp;alloc]&nbsp;initWithContentOfFile:path];&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">UIImage&nbsp;*smallImage&nbsp;=&nbsp;[self&nbsp;resizeImage:fullscreenImage];&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[fullscreenImage&nbsp;release];&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">imageView.image&nbsp;=&nbsp;smallImage;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">......&nbsp;&nbsp;</li></ol></div>&nbsp;<p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">5. 循环中大量生成的自动释放autorelease对象，可以考虑使用autorelease pool封装</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">代码范例：</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"></p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #ffffff; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.1875px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">C代码&nbsp;<embed wmode="transparent" src="http://anxonli.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" width="14" height="15" flashvars="clipboard=for(UIView%20*subview%20in%20bigView.subviews)%20%7B%0A%20%20%20%20%2F%2F%20%E4%BD%BF%E7%94%A8autorelease%20pool%E8%87%AA%E5%8A%A8%E9%87%8A%E6%94%BE%E5%AF%B9%E8%B1%A1%E6%B1%A0%0A%20%20%20%20NSAutoreleasePool%20*pool%20%3D%20%5B%5BNSAutoreleasePool%20alloc%5D%20init%5D%3B%0A%0A%20%20%20%20UIImageView%20*imageView%20%3D%20(UIImageView%20*)subview%3B%0A%20%20%20%20%0A%20%20%20%20%2F%2F%20subview%E5%A4%84%E7%90%86%E4%BB%A3%E7%A0%81%0A%20%20%20%20.......%0A%0A%20%20%20%20%2F%2F%20%E9%94%80%E6%AF%81%E8%87%AA%E5%8A%A8%E9%87%8A%E6%94%BE%E5%AF%B9%E8%B1%A1%0A%20%20%20%20%5Bpool%20%20drain%5D%3B%0A%7D" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">&nbsp;<a href="" title="收藏这段代码" style="color: #108ac6;"><img src="http://anxonli.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">for</span>(UIView&nbsp;*subview&nbsp;in&nbsp;bigView.subviews)&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="width: auto; border-width: 0px;">//&nbsp;使用autorelease&nbsp;pool自动释放对象池</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;NSAutoreleasePool&nbsp;*pool&nbsp;=&nbsp;[[NSAutoreleasePool&nbsp;alloc]&nbsp;init];&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;UIImageView&nbsp;*imageView&nbsp;=&nbsp;(UIImageView&nbsp;*)subview;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="width: auto; border-width: 0px;">//&nbsp;subview处理代码</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;.......&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="width: auto; border-width: 0px;">//&nbsp;销毁自动释放对象</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;[pool&nbsp;&nbsp;drain];&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">}&nbsp;&nbsp;</li></ol></div><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;自动释放对象池把每个循环内生成的临时对象使用完后立即释放</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">以上的意见是本人多年来编写iPad/iPhone程序的经验，另外iOS4.0的multi-tasking特性发布后，程序可以被调入后台运行，苹果工程师的意见是，进入后台运行时，你的应用应该释放掉能释放的对象，尽量保持在16M左右，这样别的程序运行时才不容易把你的应用挤掉。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">--------------------------------------------------</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">太久没有写东西了，中文写作能力退步了，大家别见怪，多给给意见</p><img src ="http://www.cppblog.com/lauer3912/aggbug/195252.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2012-11-16 06:46 <a href="http://www.cppblog.com/lauer3912/archive/2012/11/16/195252.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>python文件目录遍历保存成xml文件代码</title><link>http://www.cppblog.com/lauer3912/archive/2012/07/12/182990.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Thu, 12 Jul 2012 05:30:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2012/07/12/182990.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/182990.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2012/07/12/182990.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/182990.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/182990.html</trackback:ping><description><![CDATA[<div style="margin: 0px auto; width: 650px; height: 2133px; line-height: 30px; padding-top: 10px; overflow: hidden; font-family: Simsun; "><div><br /><a href="http://www.111cn.net/phper/python/41845.htm">http://www.111cn.net/phper/python/41845.htm</a><br />Linux服务器有CentOS、Fedora等，都预先安装了Python，版本从2.4到2.5不等，而Windows类型的服务器也多数安装了Python，因此只要在本机写好一个脚本，上传到对应机器，在运行时修改参数即可。</div><div id="c_ads5" style="width: 300px; overflow: hidden; height: 270px; float: left; "><iframe id="cproIframe3" src="http://cpro.baidu.com/cpro/ui/uijs.php?tu=u179420&amp;tn=text_default_300_250&amp;n=mailangel123_cpr&amp;rsi1=250&amp;rsi0=300&amp;rad=&amp;rss0=%23FFFFFF&amp;rss1=%23FFFFFF&amp;rss2=%230000ff&amp;rss3=%23444444&amp;rss4=%23008000&amp;rss5=&amp;rss6=%23e10900&amp;rsi5=4&amp;ts=1&amp;at=6&amp;ch=0&amp;cad=1&amp;aurl=&amp;rss7=&amp;cpa=1&amp;fv=11&amp;cn=0&amp;if=16&amp;word=http%3A%2F%2Fwww.111cn.net%2Fphper%2Fpython%2F41845.htm&amp;refer=http%3A%2F%2Fwww.google.com.hk%2Furl%3Fsa%3Dt%26rct%3Dj%26q%3Dpython%2B%25E9%2581%258D%25E5%258E%2586%25E7%259B%25AE%25E5%25BD%2595%2B%25E5%2588%259B%25E5%25BB%25BAxml%26source%3Dweb%26cd%3D8%26ved%3D0CF0QFjAH%26url%3Dhttp%253A%252F%252Fwww.111cn.net%252Fphper%252Fpython%252F41845.htm%26ei%3Djl_-T62LNOaSiAeygfH_Bg%26usg%3DAFQjCNGFh_eDkGDefnKTWgvBPPCq7TZsEQ&amp;ready=1&amp;jk=2a51083d8168227a&amp;jn=3&amp;lmt=1335495997&amp;csp=1366,768&amp;csn=1366,708&amp;ccd=32&amp;chi=1&amp;cja=true&amp;cpl=39&amp;cmi=103&amp;cce=true&amp;csl=zh-CN&amp;did=3&amp;rt=6&amp;dt=1342070706&amp;ev=50331648&amp;c01=0&amp;prt=1342070706219" width="300" height="250" align="center,center" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" allowtransparency="true"></iframe></div><div id="c_ads6" style="width: 350px; overflow: hidden; height: 270px; float: right; text-align: center; "><iframe id="cproIframe4" src="http://cpro.baidu.com/cpro/ui/uijs.php?tu=u179420&amp;tn=text_default_300_250&amp;n=mailangel123_cpr&amp;rsi1=250&amp;rsi0=300&amp;rad=&amp;rss0=%23FFFFFF&amp;rss1=%23FFFFFF&amp;rss2=%230000ff&amp;rss3=%23444444&amp;rss4=%23008000&amp;rss5=&amp;rss6=%23e10900&amp;rsi5=4&amp;ts=1&amp;at=6&amp;ch=0&amp;cad=1&amp;aurl=&amp;rss7=&amp;cpa=1&amp;fv=11&amp;cn=0&amp;if=16&amp;word=http%3A%2F%2Fwww.111cn.net%2Fphper%2Fpython%2F41845.htm&amp;refer=http%3A%2F%2Fwww.google.com.hk%2Furl%3Fsa%3Dt%26rct%3Dj%26q%3Dpython%2B%25E9%2581%258D%25E5%258E%2586%25E7%259B%25AE%25E5%25BD%2595%2B%25E5%2588%259B%25E5%25BB%25BAxml%26source%3Dweb%26cd%3D8%26ved%3D0CF0QFjAH%26url%3Dhttp%253A%252F%252Fwww.111cn.net%252Fphper%252Fpython%252F41845.htm%26ei%3Djl_-T62LNOaSiAeygfH_Bg%26usg%3DAFQjCNGFh_eDkGDefnKTWgvBPPCq7TZsEQ&amp;ready=1&amp;jk=62b1a21389f8475f&amp;jn=3&amp;lmt=1335495997&amp;csp=1366,768&amp;csn=1366,708&amp;ccd=32&amp;chi=1&amp;cja=true&amp;cpl=39&amp;cmi=103&amp;cce=true&amp;csl=zh-CN&amp;did=4&amp;rt=4&amp;dt=1342070706&amp;pn=3|text_default_300_250|6&amp;ev=50331648&amp;c01=0&amp;prt=1342070706219" width="300" height="250" align="center,center" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" allowtransparency="true"></iframe></div><p style="margin: 0px; padding: 0px; line-height: 24px; ">Python操作文件和文件夹使用的是os库，下面的代码中主要用到了几个函数：</p><p style="margin: 0px; padding: 0px; line-height: 24px; ">os.listdir:列出目录下的文件和文件夹</p><p style="margin: 0px; padding: 0px; line-height: 24px; ">os.path.join:拼接得到一个文件/文件夹的全路径</p><p style="margin: 0px; padding: 0px; line-height: 24px; ">os.path.isfile:判断是否是文件</p><p style="margin: 0px; padding: 0px; line-height: 24px; ">os.path.splitext：从名称中取出一个子部分</p><p style="margin: 0px; padding: 0px; line-height: 24px; ">&nbsp;</p><p style="margin: 0px; padding: 0px; line-height: 24px; ">下面是目录操作的代码</p><table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="margin: 20px 0px; background-color: #ffbb77; background-position: initial initial; background-repeat: initial initial; "><tbody><tr><td width="464" height="27" bgcolor="#FFE7CE" style="font-size: 12px; ">&nbsp;代码如下</td><td width="109" align="center" bgcolor="#FFE7CE" style="font-size: 12px; cursor: pointer; ">复制代码</td></tr><tr><td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" id="copy4447" style="font-size: 14px; line-height: 26px; background-color: #fff4e8; padding: 10px; ">def search(folder, filter, allfile):<br />&nbsp;&nbsp;&nbsp; folders = os.listdir(folder)<br />&nbsp;&nbsp;&nbsp; for name in folders:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; curname = os.path.join(folder, name)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; isfile = os.path.isfile(curname)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if isfile:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ext = os.path.splitext(curname)[1]<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; count = filter.count(ext)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if count&gt;0:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cur = myfile()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cur.name = curname<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; allfile.append(cur)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; search(curname, filter, allfile)<br />&nbsp;&nbsp;&nbsp; return allfile</td></tr></tbody></table><p style="margin: 0px; padding: 0px; line-height: 24px; ">在返回文件的各种信息时，使用自定义类allfile来保存文件的信息，在程序中只用到了文件的全路径，如果需要同时记录文件的大小、时间、类型等信息，可以仿照代码进行扩充。</p><table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="margin: 20px 0px; background-color: #ffbb77; background-position: initial initial; background-repeat: initial initial; "><tbody><tr><td width="464" height="27" bgcolor="#FFE7CE" style="font-size: 12px; ">&nbsp;代码如下</td><td width="109" align="center" bgcolor="#FFE7CE" style="font-size: 12px; cursor: pointer; ">复制代码</td></tr><tr><td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" id="copy3518" style="font-size: 14px; line-height: 26px; background-color: #fff4e8; padding: 10px; "><p style="margin: 0px; padding: 0px; line-height: 24px; ">class myfile:<br />&nbsp;&nbsp;&nbsp; def __init__(self):<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.name = ""</p></td></tr></tbody></table><p style="margin: 0px; padding: 0px; line-height: 24px; ">得到存储文件信息的数组后，还可以将其另存成xml格式，下面是代码，在使用时，需要从Document中导入xml.dom.minidom</p><p style="margin: 0px; padding: 0px; line-height: 24px; ">下面是保存为xml的代码</p><table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="margin: 20px 0px; background-color: #ffbb77; background-position: initial initial; background-repeat: initial initial; "><tbody><tr><td width="464" height="27" bgcolor="#FFE7CE" style="font-size: 12px; ">&nbsp;代码如下</td><td width="109" align="center" bgcolor="#FFE7CE" style="font-size: 12px; cursor: pointer; ">复制代码</td></tr><tr><td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" id="copy1269" style="font-size: 14px; line-height: 26px; background-color: #fff4e8; padding: 10px; "><p style="margin: 0px; padding: 0px; line-height: 24px; ">def generate(allfile, xml):<br />&nbsp;&nbsp;&nbsp; doc = Document()</p><p style="margin: 0px; padding: 0px; line-height: 24px; ">&nbsp;&nbsp;&nbsp; root = doc.createElement("root")<br />&nbsp;&nbsp;&nbsp; doc.appendChild(root)</p><p style="margin: 0px; padding: 0px; line-height: 24px; ">&nbsp;&nbsp;&nbsp; for myfile in allfile:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; file = doc.createElement("file")<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; root.appendChild(file)</p><p style="margin: 0px; padding: 0px; line-height: 24px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name = doc.createElement("name")<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; file.appendChild(name)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; namevalue = doc.createTextNode(myfile.name)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name.appendChild(namevalue)</p><p style="margin: 0px; padding: 0px; line-height: 24px; ">&nbsp;&nbsp;&nbsp; print doc.toprettyxml(indent="")<br />&nbsp;&nbsp;&nbsp; f = open(xml, 'a+')<br />&nbsp;&nbsp;&nbsp; f.write(doc.toprettyxml(indent=""))<br />&nbsp;&nbsp;&nbsp; f.close()</p></td></tr></tbody></table><p style="margin: 0px; padding: 0px; line-height: 24px; ">执行的代码如下</p><table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="margin: 20px 0px; background-color: #ffbb77; background-position: initial initial; background-repeat: initial initial; "><tbody><tr><td width="464" height="27" bgcolor="#FFE7CE" style="font-size: 12px; ">&nbsp;代码如下</td><td width="109" align="center" bgcolor="#FFE7CE" style="font-size: 12px; cursor: pointer; ">复制代码</td></tr><tr><td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" id="copy5227" style="font-size: 14px; line-height: 26px; background-color: #fff4e8; padding: 10px; "><p style="margin: 0px; padding: 0px; line-height: 24px; ">if __name__ == '__main__':<br />&nbsp;&nbsp;&nbsp; folder = "/usr/local/apache/htdocs"<br />&nbsp;&nbsp;&nbsp; filter = [".html",".htm",".<a href="http://www.111cn.net/phper/php.html" target="_blank" style="font-size: 12px; color: #333333; text-decoration: none; ">php</a>"]<br />&nbsp;&nbsp;&nbsp; allfile = []<br />&nbsp;&nbsp;&nbsp; allfile = search(folder, filter, allfile)<br />&nbsp;&nbsp;&nbsp; len = len(allfile)<br />&nbsp;&nbsp;&nbsp; print "found: " + str(len) + " files"</p><p style="margin: 0px; padding: 0px; line-height: 24px; ">&nbsp;&nbsp;&nbsp; xml = "folder.xml"<br />&nbsp;&nbsp;&nbsp; generate(allfile, xml)</p></td></tr></tbody></table><p style="margin: 0px; padding: 0px; line-height: 24px; ">在Linux命令行状态下，执行Python filesearch.py，便可以生成名为folder.xml的文件。</p><p style="margin: 0px; padding: 0px; line-height: 24px; ">如果要在Windows中运行该程序，需要把folder变量改成Windows下的格式，例如c:\apache2htdocs，然后执行c:python25python.exe filesearch.py（这里假设python的安装目录是c:python25）</p></div><div id="c_ads4" style="margin: 0px 20px 0px 40px; text-align: center; font-family: Simsun; font-size: 12px; line-height: normal; "></div><img src ="http://www.cppblog.com/lauer3912/aggbug/182990.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2012-07-12 13:30 <a href="http://www.cppblog.com/lauer3912/archive/2012/07/12/182990.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Object-C学习笔记 基础部分(一)NSString常用方法</title><link>http://www.cppblog.com/lauer3912/archive/2012/05/29/176653.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Tue, 29 May 2012 13:59:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2012/05/29/176653.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/176653.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2012/05/29/176653.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/176653.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/176653.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: http://keys.iteye.com/blog/1117190个人学习笔记&nbsp;NSString&nbsp;--实例化方法--------------&nbsp;NSString *str = [[NSString alloc] init];&nbsp;NSString *str = [[[NSString alloc] init] autorelease];&nbsp;&nbsp;&...&nbsp;&nbsp;<a href='http://www.cppblog.com/lauer3912/archive/2012/05/29/176653.html'>阅读全文</a><img src ="http://www.cppblog.com/lauer3912/aggbug/176653.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2012-05-29 21:59 <a href="http://www.cppblog.com/lauer3912/archive/2012/05/29/176653.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>XCODE 4.3 WITH NO GCC?</title><link>http://www.cppblog.com/lauer3912/archive/2012/04/07/170388.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Sat, 07 Apr 2012 13:50:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2012/04/07/170388.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/170388.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2012/04/07/170388.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/170388.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/170388.html</trackback:ping><description><![CDATA[<p style="color: #333333; margin-top: 8px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; word-break: break-all; line-height: 26px; font-family: Simsun; text-align: left; background-color: #ffffff; ">真的坑爹，今天才开始玩MAC OX，装了个最新版本的10.7.3，只能装XCODE 4.3 这个月刚发行的版本。</p><p style="color: #333333; margin-top: 8px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; word-break: break-all; line-height: 26px; font-family: Simsun; text-align: left; background-color: #ffffff; ">安装时发现没有install过程，直接双击就进入开发环境了。而且装完后没有gcc 等各种编译工具，在TERMINAL下各种命令不识别，想装ruby的各种开发工具，都不行了。</p><p style="color: #333333; margin-top: 8px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; word-break: break-all; line-height: 26px; font-family: Simsun; text-align: left; background-color: #ffffff; ">&nbsp;</p><p style="color: #333333; margin-top: 8px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; word-break: break-all; line-height: 26px; font-family: Simsun; text-align: left; background-color: #ffffff; ">查了半天才发现：</p><p style="color: #333333; margin-top: 8px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; word-break: break-all; line-height: 26px; font-family: Simsun; text-align: left; background-color: #ffffff; ">Apple announced Xcode 4.3 for OSX Lion and 4.4 for OSX Mountain Lion last week. The major difference is that Xcode no longer provide an installer which is good thing because you now could update Xcode with AppStore in the future, plus it is much easier to carry the development environment with you. However, there is a little problem with this new version of Xcode, is that all command line toolsets and compilers are not visible in terminal.&nbsp;<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " /><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />解决方案一：<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />A simple fix is to update your PATH env:</p><p style="color: #333333; margin-top: 8px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; word-break: break-all; line-height: 26px; font-family: Simsun; text-align: left; background-color: #ffffff; "><code style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">export PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:$PATH</code></p><p style="color: #333333; margin-top: 8px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; word-break: break-all; line-height: 26px; font-family: Simsun; text-align: left; background-color: #ffffff; ">Please be noted that clang does not reside in /Developer/usr/bin, it is now in /Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin</p><p style="color: #333333; margin-top: 8px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; word-break: break-all; line-height: 26px; font-family: Simsun; text-align: left; background-color: #ffffff; ">Now you could access to gcc, g++, git or any toolsets bundled with Xcode. For your convenience, it is recommended to include it in your&nbsp;<code style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">.bash_profile</code>.</p><p style="color: #333333; margin-top: 8px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; word-break: break-all; line-height: 26px; font-family: Simsun; text-align: left; background-color: #ffffff; ">解决方案二：</p><p style="color: #333333; margin-top: 8px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; word-break: break-all; line-height: 26px; font-family: Simsun; text-align: left; background-color: #ffffff; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">You can install these additional tools directly in Xcode :</span><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " /><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">Preferences &gt; Downloads &gt; Command Line Tools &gt; Install</span></p><p style="color: #333333; margin-top: 8px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; word-break: break-all; line-height: 26px; font-family: Simsun; text-align: left; background-color: #ffffff; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " /></span></p><p style="color: #333333; margin-top: 8px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; word-break: break-all; line-height: 26px; font-family: Simsun; text-align: left; background-color: #ffffff; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">SO. What a fUUUcking day！</span></p><img src ="http://www.cppblog.com/lauer3912/aggbug/170388.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2012-04-07 21:50 <a href="http://www.cppblog.com/lauer3912/archive/2012/04/07/170388.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>全民吃苹果，首发VirtualBOX安装Mac OS X 10.7正式版_可完美升级，无bug</title><link>http://www.cppblog.com/lauer3912/archive/2012/04/07/170325.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Fri, 06 Apr 2012 23:45:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2012/04/07/170325.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/170325.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2012/04/07/170325.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/170325.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/170325.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 原文：http://ideapad.zol.com.cn/56/160_557572.html灵感来了的时候，挡也挡不住，这个是真的！昨晚一个很偶然的机会下，我使用Vmware 8 安装成功了Mac OS X 10.7（Lion）系统，实在是让人非常兴奋。再三申明，本人的电脑就是那种装黑苹果被判了死刑的电脑。关于死&#8212;&#8212;乔布斯是这么说的&#8220;没有人愿意死，即使想上天堂...&nbsp;&nbsp;<a href='http://www.cppblog.com/lauer3912/archive/2012/04/07/170325.html'>阅读全文</a><img src ="http://www.cppblog.com/lauer3912/aggbug/170325.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2012-04-07 07:45 <a href="http://www.cppblog.com/lauer3912/archive/2012/04/07/170325.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>VMware虚拟机更新Mac OS Lion 10.7.2后无法正常启动解决方案</title><link>http://www.cppblog.com/lauer3912/archive/2012/04/07/170323.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Fri, 06 Apr 2012 23:32:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2012/04/07/170323.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/170323.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2012/04/07/170323.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/170323.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/170323.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 原文：http://ideapad.zol.com.cn/57/160_560764.html楼主我之前发过的Vmware 8和VirtualBOX 安装Lion的教程。1、全民吃苹果，首发VirtualBOX安装Mac OS X 10.7正式版_可完美升级，无bug&nbsp;http://ideapad.zol.com.cn/56/160_557572.html2、踏破铁鞋，Vmware 8完...&nbsp;&nbsp;<a href='http://www.cppblog.com/lauer3912/archive/2012/04/07/170323.html'>阅读全文</a><img src ="http://www.cppblog.com/lauer3912/aggbug/170323.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2012-04-07 07:32 <a href="http://www.cppblog.com/lauer3912/archive/2012/04/07/170323.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>踏破铁鞋，Vmware 8完美安装Mac Lion狮子系统，CPU不支持虚拟化，键盘无响经验共享</title><link>http://www.cppblog.com/lauer3912/archive/2012/04/07/170322.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Fri, 06 Apr 2012 23:30:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2012/04/07/170322.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/170322.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2012/04/07/170322.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/170322.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/170322.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 原文：http://ideapad.zol.com.cn/56/160_557421.html本楼层&nbsp;是虚拟机设置贴子一楼是 Mac安装帖子二楼是 工具下载位置，希望童鞋不要和我抢沙发神舟A560P i7-D2（Windows 7 X64环境下，VMware 8.0正式版）虚拟机首尝MAC OS X 10.7 Lion系统成功，特将此好消息分享。2年了，终于我也装上了Mac，我也成功的尝...&nbsp;&nbsp;<a href='http://www.cppblog.com/lauer3912/archive/2012/04/07/170322.html'>阅读全文</a><img src ="http://www.cppblog.com/lauer3912/aggbug/170322.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2012-04-07 07:30 <a href="http://www.cppblog.com/lauer3912/archive/2012/04/07/170322.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C++查缺补漏4，赶紧的</title><link>http://www.cppblog.com/lauer3912/archive/2012/04/05/170159.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Thu, 05 Apr 2012 06:54:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2012/04/05/170159.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/170159.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2012/04/05/170159.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/170159.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/170159.html</trackback:ping><description><![CDATA[<div id="cnblogs_post_body" style="line-height: 1.8; color: #333333; font-family: Verdana,Arial,sans-serif,'Lucida Grande'; font-size: 13px; text-align: left; background-color: #d6d3d6;"><p><span style="color: #0000ff; font-family: 楷体_GB2312; font-size: medium; ">请说出const与#define 相比，有何优点？<br />答案：</span><span style="color: #0000ff; font-family: 楷体_GB2312; font-size: medium; ">1）&nbsp;<strong>const 常量有数据类型，而宏常量没有数据类型</strong>。编译器可以对前者进行类型<strong>安全检查</strong>。而对后者只进行字符替换，没有类型安全检查，并且在字符替换可能会产生意料不到的错误。<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2）&nbsp;<strong>有些集成化的调试工具可以对const 常量进行调试</strong>，但是不能对宏常量进行调试。</span></p><p><span style="color: #0000ff; font-family: 楷体_GB2312; font-size: medium; ">在8086 汇编下，逻辑地址和物理地址是怎样转换的？（Intel）<br />答案：通用寄存器给出的地址，是段内偏移地址，相应段寄存器地址*10H+通用寄存器内地址，就得到了真正要访问的地址。</span></p><p><span style="color: #0000ff; font-family: 楷体_GB2312; font-size: medium; ">当一个类A 中没有生命任何成员变量与成员函数,这时sizeof(A)的值是多少，如果不是零，请解释一下编译器为什么没有让它为零。（Autodesk）<br />答案：肯定不是零。举个反例，如果是零的话，声明一个class A[10]对象数组，而每一个对象占用的空间是零，这时就没办法区分A[0],A[1]&#8230;了。</span></p><p><span style="color: #0000ff; font-family: 楷体_GB2312; font-size: medium; ">&nbsp;描述内存分配方式以及它们的区别?<br />1）<strong>&nbsp;从静态存储区域分配</strong>。内存在程序编译的时候就已经分配好，这块内存在程序的整个运行期间都存在。例如<strong>全局变量，static 变量</strong>。<br />2）&nbsp;<strong>在栈上创建</strong>。在执行函数时，<strong>函数内局部变量的存储单元都可以在栈上创建</strong>，函数执行结束时这些存储单元自动被释放。栈内存分配运算内置于处理器的指令集。<br />3）&nbsp;<strong>从堆上分配</strong>，<strong>亦称动态内存分配</strong>。程序在运行的时候用malloc 或new 申请任意多少的内存，程序员自己负责在何时用free 或delete 释放内存。动态内存的生存期由程序员决定，使用非常灵活，但问题也最多。</span></p><p><span style="color: #0000ff; font-family: 楷体_GB2312; font-size: medium; ">&nbsp;main 函数执行以前，还会执行什么代码？<br />答案：全局对象的构造函数会在main 函数之前执行。</span></p><p><span style="color: #0000ff; font-family: 楷体_GB2312; font-size: medium; ">&nbsp;C++是不是类型安全的？<br />答案：不是。两个不同类型的指针之间可以强制转换（用reinterpret cast)。C#是类型安全的。</span></p><p>&nbsp;</p><p><span style="color: #3300ff; font-family: 楷体_GB2312; font-size: medium; ">有哪几种情况只能用intialization list 而不能用assignment?</span></p><p>&nbsp;</p><p><span style="color: #3300ff; font-family: 楷体_GB2312; font-size: medium; ">答案：当类中含有const、reference 成员变量；基类的构造函数都需要初始化表。</span></p><p><span style="color: #3300ff; font-family: 楷体_GB2312; font-size: medium; ">define DOUBLE(x) x+x ，i = 5*DOUBLE(5)； i 是多少？<br />答案：i 为30</span></p><p><span style="color: #3300ff; font-family: 楷体_GB2312; font-size: medium; ">New delete 与malloc free 的联系与区别?<br />答案：都是在堆(heap)上进行动态的内存操作。用malloc函数需要指定内存分配的字节数并且不能初始化对象，new 会自动调用对象的构造函数。delete 会调用对象的destructor，而free 不会调用对象的destructor.</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">1、写一个&#8220;标准&#8221;宏，这个宏输入两个参数并返回较小的一个。<br />.#define Min(X, Y) ((X)&gt;(Y)?(Y):(X))//结尾没有;<br />2、嵌入式系统中经常要用到无限循环，你怎么用C编写死循环。<br />while(1){}或者for(;;)<br />3、关键字static的作用是什么？<br />定义静态变量<br />4、关键字const有什么含意？<br />表示常量不可以修改的变量。<br />5、关键字volatile有什么含意？并举出三个不同的例子？<br />提示编译器对象的值可能在编译器未监测到的情况下改变。</span></p><p>&nbsp;</p><p><br /><span style="color: #4822dd; ">int (*s[10])(int) 表示的是什么啊<br />int (*s[10])(int) 函数指针数组，每个指针指向一个int func(int param)的函数。</span></p><p>&nbsp;</p><p><br /><span style="color: #4822dd; ">1.有以下表达式：<br />int a=248; b=4;int const c=21;const int *d=&amp;a;<br />int *const e=&amp;b;int const *f const =&amp;a;<br />请问下列表达式哪些会被编译器禁止？为什么？<br />*c=32;d=&amp;b;*d=43;e=34;e=&amp;a;f=0x321f;<br />*c 这是个什么东东，禁止<br />*d 说了是const， 禁止<br />e = &amp;a 说了是const 禁止<br />const *f const =&amp;a; 禁止<br />2.交换两个变量的值，不使用第三个变量。即a=3,b=5,交换之后a=5,b=3;<br />有两种解法, 一种用算术算法, 一种用^(异或)<br />a = a + b;<br />b = a - b;<br />a = a - b;&nbsp;<br />or<br />a = a^b;// 只能对int,char..<br />b = a^b;<br />a = a^b;<br />or<br />a ^= b ^= a;<br />3.c和c++中的struct有什么不同？<br />c和c++中struct的主要区别是c中的struct不可以含有成员函数，而c++中的struct可以。c++中struct和class的主要区别在于默认的存取权限不同，struct默认为public，而class默认为private<br />4.＃i nclude &lt;stdio.h&gt;<br />＃i nclude &lt;stdlib.h&gt;<br />void getmemory(char *p)<br />{<br />&nbsp;&nbsp;&nbsp; p=(char *) malloc(100);<br />&nbsp;&nbsp;&nbsp; strcpy(p,"hello world");<br />}<br />int main( )<br />{<br />&nbsp;&nbsp;&nbsp; char *str=NULL;<br />&nbsp;&nbsp;&nbsp; getmemory(str);<br />&nbsp;&nbsp;&nbsp; printf("%s/n",str);<br />&nbsp;&nbsp;&nbsp; free(str);<br />&nbsp;&nbsp;&nbsp; return 0;<br />&nbsp;&nbsp; }<br />程序崩溃，getmemory中的malloc 不能返回动态内存， free（）对str操作很危险<br />5.char szstr[10];<br />strcpy(szstr,"0123456789");<br />产生什么结果？为什么？<br />长度不一样，会造成非法的OS<br />6.列举几种进程的同步机制，并比较其优缺点。<br />&nbsp;&nbsp; 原子操作&nbsp;<br />信号量机制<br />&nbsp;&nbsp; 自旋锁<br />&nbsp;&nbsp; 管程，会合，分布式系统</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">7.进程之间通信的途径<br />共享存储系统<br />消息传递系统<br />管道：以文件系统为基础<br />11.进程死锁的原因<br />资源竞争及进程推进顺序非法<br />12.死锁的4个必要条件<br />互斥、请求保持、不可剥夺、环路<br />13.死锁的处理<br />鸵鸟策略、预防策略、避免策略、检测与解除死锁<br />15.&nbsp;&nbsp; 操作系统中进程调度策略有哪几种？<br />FCFS(先来先服务)，优先级，时间片轮转，多级反馈<br />8.类的静态成员和非静态成员有何区别？<br />类的静态成员每个类只有一个，非静态成员每个对象一个<br />9.纯虚函数如何定义？使用时应注意什么？<br />virtual void f()=0;<br />是接口，子类必须要实现<br />10.数组和链表的区别<br />数组：数据顺序存储，固定大小<br />连表：数据可以随机存储，大小可动态改变</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">12.ISO的七层模型是什么？tcp/udp是属于哪一层？tcp/udp有何优缺点？<br />应用层<br />表示层<br />会话层<br />运输层<br />网络层<br />物理链路层<br />物理层<br />tcp /udp属于运输层<br />TCP 服务提供了数据流传输、可靠性、有效流控制、全双工操作和多路复用技术等。<br />与 TCP 不同， UDP 并不提供对 IP 协议的可靠机制、流控制以及错误恢复功能等。由于 UDP 比较简单， UDP 头包含很少的字节，比 TCP 负载消耗少。<br />tcp: 提供稳定的传输服务，有流量控制，缺点是包头大，冗余性不好<br />udp: 不提供稳定的服务，包头小，开销小&nbsp;&nbsp;</span></p><p>&nbsp;</p><p><br /><span style="color: #4822dd; ">1：(void *)ptr 和 (*(void**))ptr的结果是否相同？其中ptr为同一个指针<br />.(void *)ptr 和 (*(void**))ptr值是相同的<br />2：int main()<br />&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp; int x=3;<br />&nbsp;&nbsp;&nbsp; printf("%d",x);<br />&nbsp;&nbsp;&nbsp; return 1;<br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp; }<br />问函数既然不会被其它函数调用，为什么要返回1？<br />mian中，c标准认为0表示成功，非0表示错误。具体的值是某中具体出错信息</span></p><p>&nbsp;</p><p><br /><span style="color: #4822dd; ">1，要对绝对地址0x100000赋值，我们可以用<br />(unsigned int*)0x100000 = 1234;<br />那么要是想让程序跳转到绝对地址是0x100000去执行，应该怎么做？<br />*((void (*)( ))0x100000 ) ( );<br />首先要将0x100000强制转换成函数指针,即:<br />(void (*)())0x100000<br />然后再调用它:<br />*((void (*)())0x100000)();<br />用typedef可以看得更直观些:<br />typedef void(*)() voidFuncPtr;<br />*((voidFuncPtr)0x100000)();<br />2，已知一个数组table，用一个宏定义，求出数据的元素个数<br />#define NTBL<br />#define NTBL (sizeof(table)/sizeof(table[0]))</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">面试题: 线程与进程的区别和联系? 线程是否具有相同的堆栈? dll是否有独立的堆栈?<br />进程是死的，只是一些资源的集合，真正的程序执行都是线程来完成的，程序启动的时候操作系统就帮你创建了一个主线程。</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">每个线程有自己的堆栈。<br />DLL中有没有独立的堆栈，这个问题不好回答，或者说这个问题本身是否有问题。因为DLL中的代码是被某些线程所执行，只有线程拥有堆栈，如果DLL中的代码是EXE中的线程所调用，那么这个时候是不是说这个DLL没有自己独立的堆栈？如果DLL中的代码是由DLL自己创建的线程所执行，那么是不是说DLL有独立的堆栈？</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">以上讲的是堆栈，如果对于堆来说，每个DLL有自己的堆，所以如果是从DLL中动态分配的内存，最好是从DLL中删除，如果你从DLL中分配内存，然后在EXE中，或者另外一个DLL中删除，很有可能导致程序崩溃</span></p><p>&nbsp;</p><p><br /><span style="color: #4822dd; ">unsigned short A = 10;<br />printf("~A = %u\n", ~A);</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">char c=128;&nbsp;<br />printf("c=%d\n",c);</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">输出多少？并分析过程<br />第一题，～A ＝0xfffffff5,int值 为－11，但输出的是uint。所以输出4294967285<br />第二题，c＝0x10,输出的是int，最高位为1，是负数，所以它的值就是0x00的补码就是128，所以输出－128。<br />这两道题都是在考察二进制向int或uint转换时的最高位处理。</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">分析下面的程序：<br />void GetMemory(char **p,int num)<br />{<br />&nbsp;&nbsp;&nbsp; *p=(char *)malloc(num);<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />int main()<br />{<br />&nbsp;&nbsp;&nbsp; char *str=NULL;<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp; GetMemory(&amp;str,100);<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp; strcpy(str,"hello");<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp; free(str);<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp; if(str!=NULL)<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strcpy(str,"world");<br />&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp; printf("\n str is %s",str);<br />&nbsp;&nbsp;&nbsp; getchar();<br />}&nbsp;&nbsp;&nbsp;&nbsp;<br />问输出结果是什么？希望大家能说说原因，先谢谢了<br />输出str is world。<br />free 只是释放的str指向的内存空间,它本身的值还是存在的.<br />所以free之后，有一个好的习惯就是将str=NULL.<br />此时str指向空间的内存已被回收,如果输出语句之前还存在分配空间的操作的话,这段存储空间是可能被重新分配给其他变量的,<br />尽管这段程序确实是存在大大的问题（上面各位已经说得很清楚了），但是通常会打印出world来。<br />这是因为，进程中的内存管理一般不是由操作系统完成的，而是由库函数自己完成的。<br />当你malloc一块内存的时候，管理库向操作系统申请一块空间（可能会比你申请的大一些），然后在这块空间中记录一些管理信息（一般是在你申请的内存前面一点），并将可用内存的地址返回。但是释放内存的时候，管理库通常都不会将内存还给操作系统，因此你是可以继续访问这块地址的，只不过。。。。。。。。楼上都说过了，最好别这么干。</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">char a[10],strlen(a)为什么等于15？运行的结果</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">＃i nclude "stdio.h"<br />＃i nclude "string.h"</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">void main()<br />{</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">char aa[10];<br />printf("%d",strlen(aa));<br />}</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">sizeof()和初不初始化，没有关系；<br />strlen()和初始化有关。</span></p><p>&nbsp;</p><p><br /><span style="color: #4822dd; ">char (*str)[20];/*str是一个数组指针，即指向数组的指针．*/<br />char *str[20];/*str是一个指针数组，其元素为指针型数据．*/</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">long a=0x801010;<br />a+5=?<br />0x801010用二进制表示为：&#8220;1000 0000 0001 0000 0001 0000&#8221;，十进制的值为8392720，再加上5就是8392725罗</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">1)给定结构struct A&nbsp;<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char t:4;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char k:4;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned short i:8;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned long m;<br />};问sizeof(A) = ?<br />给定结构struct A&nbsp;<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char t:4; 4位<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char k:4; 4位<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned short i:8; 8位&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned long m; // 偏移2字节保证4字节对齐<br />}; // 共8字节<br />2)下面的函数实现在一个数上加一个数，有什么错误？请改正。<br />int add_n ( int n )<br />{<br />&nbsp;&nbsp;&nbsp; static int i = 100;<br />&nbsp;&nbsp;&nbsp; i += n;<br />&nbsp;&nbsp;&nbsp; return i;<br />}<br />当你第二次调用时得不到正确的结果，难道你写个函数就是为了调用一次？问题就出在 static上？</span></p><p>&nbsp;</p><p><br /><span style="color: #4822dd; ">// 帮忙分析一下<br />＃i nclude&lt;iostream.h&gt;<br />＃i nclude &lt;string.h&gt;<br />＃i nclude &lt;malloc.h&gt;<br />＃i nclude &lt;stdio.h&gt;<br />＃i nclude &lt;stdlib.h&gt;<br />＃i nclude &lt;memory.h&gt;<br />typedef struct AA<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int b1:5;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int b2:2;<br />}AA;<br />void main()<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AA aa;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char cc[100];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strcpy(cc,"0123456789abcdefghijklmnopqrstuvwxyz");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; memcpy(&amp;aa,cc,sizeof(AA));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cout &lt;&lt; aa.b1 &lt;&lt;endl;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cout &lt;&lt; aa.b2 &lt;&lt;endl;<br />}<br />答案是 -16和１<br />首先sizeof(AA)的大小为4,b1和b2分别占5bit和2bit.<br />经过strcpy和memcpy后,aa的4个字节所存放的值是:<br />0,1,2,3的ASC码，即00110000,00110001,00110010,00110011<br />所以，最后一步：显示的是这４个字节的前５位，和之后的２位<br />分别为：10000,和01<br />因为int是有正负之分　　所以：答案是-16和１</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">求函数返回值，输入x=9999;&nbsp;<br />int func （ x ）<br />{&nbsp;<br />&nbsp;&nbsp;&nbsp; int countx = 0;&nbsp;<br />&nbsp;&nbsp;&nbsp; while ( x )&nbsp;<br />&nbsp;&nbsp;&nbsp; {&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; countx ++;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x = x&amp;(x-1);&nbsp;<br />&nbsp;&nbsp;&nbsp; }&nbsp;<br />&nbsp;&nbsp;&nbsp; return countx;&nbsp;<br />}&nbsp;<br />结果呢？<br />知道了这是统计9999的二进制数值中有多少个1的函数，且有<br />9999＝9&#215;1024＋512＋256＋15</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">9&#215;1024中含有1的个数为2；<br />512中含有1的个数为1；<br />256中含有1的个数为1；<br />15中含有1的个数为4；<br />故共有1的个数为8，结果为8。<br />1000 - 1 = 0111，正好是原数取反。这就是原理。<br />用这种方法来求1的个数是很效率很高的。<br />不必去一个一个地移位。循环次数最少。</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">int a,b,c 请写函数实现C=a+b ,不可以改变数据类型,如将c改为long int,关键是如何处理溢出问题<br />bool add (int a, int b,int *c)<br />{<br />*c=a+b;<br />return (a&gt;0 &amp;&amp; b&gt;0 &amp;&amp;(*c&lt;a || *c&lt;b) || (a&lt;0 &amp;&amp; b&lt;0 &amp;&amp;(*c&gt;a || *c&gt;b)));<br />}</span></p><p>&nbsp;</p><p><br /><span style="color: #4822dd; ">分析：<br />struct bit&nbsp;<br />{&nbsp;&nbsp; int a:3;&nbsp;<br />&nbsp;&nbsp;&nbsp; int b:2;&nbsp;<br />&nbsp;&nbsp;&nbsp; int c:3;&nbsp;<br />};&nbsp;<br />int main()&nbsp;<br />{&nbsp;<br />bit s;&nbsp;<br />char *c=(char*)&amp;s;&nbsp;<br />&nbsp;&nbsp; cout&lt;&lt;sizeof(bit)&lt;&lt;endl;<br />*c=0x99;<br />&nbsp;&nbsp; cout &lt;&lt; s.a &lt;&lt;endl &lt;&lt;s.b&lt;&lt;endl&lt;&lt;s.c&lt;&lt;endl;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; int a=-1;<br />&nbsp;&nbsp; printf("%x",a);<br />return 0;&nbsp;<br />}&nbsp;<br />输出为什么是<br />4<br />1<br />-1<br />-4<br />ffffffff<br />因为0x99在内存中表示为 100 11 001 , a = 001, b = 11, c = 100<br />当c为有符合数时, c = 100, 最高1为表示c为负数，负数在计算机用补码表示，所以c = -4;同理&nbsp;<br />b = -1;<br />当c为有符合数时, c = 100,即 c = 4,同理 b = 3</span></p><p>&nbsp;</p><p><br /><span style="color: #4822dd; ">位域 ：&nbsp;&nbsp;&nbsp;<br />有些信息在存储时，并不需要占用一个完整的字节， 而只需占几个或一个二进制位。例如在存放一个开关量时，只有0和1 两种状态， 用一位二进位即可。为了节省存储空间，并使处理简便，Ｃ语言又提供了一种数据结构，称为&#8220;位域&#8221;或&#8220;位段&#8221;。所谓&#8220;位域&#8221;是把一个字节中的二进位划分为几个不同的区域， 并说明每个区域的位数。每个域有一个域名，允许在程序中按域名进行操作。 这样就可以把几个不同的对象用一个字节的二进制位域来表示。一、位域的定义和位域变量的说明位域定义与结构定义相仿，其形式为：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />struct 位域结构名&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />{ 位域列表 };&nbsp;&nbsp;&nbsp;&nbsp;<br />其中位域列表的形式为： 类型说明符 位域名：位域长度&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />例如：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />struct bs&nbsp;&nbsp;&nbsp;&nbsp;<br />{&nbsp;&nbsp;&nbsp;&nbsp;<br />int a:8;&nbsp;&nbsp;&nbsp;&nbsp;<br />int b:2;&nbsp;&nbsp;&nbsp;&nbsp;<br />int c:6;&nbsp;&nbsp;&nbsp;&nbsp;<br />};&nbsp;&nbsp;&nbsp;&nbsp;<br />位域变量的说明与结构变量说明的方式相同。 可采用先定义后说明，同时定义说明或者直接说明这三种方式。例如：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />struct bs&nbsp;&nbsp;&nbsp;&nbsp;<br />{&nbsp;&nbsp;&nbsp;&nbsp;<br />int a:8;&nbsp;&nbsp;&nbsp;&nbsp;<br />int b:2;&nbsp;&nbsp;&nbsp;&nbsp;<br />int c:6;&nbsp;&nbsp;&nbsp;&nbsp;<br />}data;&nbsp;&nbsp;&nbsp;&nbsp;<br />说明data为bs变量，共占两个字节。其中位域a占8位，位域b占2位，位域c占6位。对于位域的定义尚有以下几点说明：&nbsp;&nbsp;&nbsp;</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">1. 一个位域必须存储在同一个字节中，不能跨两个字节。如一个字节所剩空间不够存放另一位域时，应从下一单元起存放该位域。也可以有意使某位域从下一单元开始。例如：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />struct bs&nbsp;&nbsp;&nbsp;&nbsp;<br />{&nbsp;&nbsp;&nbsp;&nbsp;<br />unsigned a:4&nbsp;&nbsp;&nbsp;&nbsp;<br />unsigned :0 /*空域*/&nbsp;&nbsp;&nbsp;&nbsp;<br />unsigned b:4 /*从下一单元开始存放*/&nbsp;&nbsp;&nbsp;&nbsp;<br />unsigned c:4&nbsp;&nbsp;&nbsp;&nbsp;<br />}&nbsp;&nbsp;&nbsp;&nbsp;<br />在这个位域定义中，a占第一字节的4位，后4位填0表示不使用，b从第二字节开始，占用4位，c占用4位。&nbsp;&nbsp;&nbsp;</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">2. 由于位域不允许跨两个字节，因此位域的长度不能大于一个字节的长度，也就是说不能超过8位二进位。&nbsp;&nbsp;&nbsp;</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">3. 位域可以无位域名，这时它只用来作填充或调整位置。无名的位域是不能使用的。例如：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />struct k&nbsp;&nbsp;&nbsp;&nbsp;<br />{&nbsp;&nbsp;&nbsp;&nbsp;<br />int a:1&nbsp;&nbsp;&nbsp;&nbsp;<br />int :2 /*该2位不能使用*/&nbsp;&nbsp;&nbsp;&nbsp;<br />int b:3&nbsp;&nbsp;&nbsp;&nbsp;<br />int c:2&nbsp;&nbsp;&nbsp;&nbsp;<br />};&nbsp;&nbsp;&nbsp;&nbsp;<br />从以上分析可以看出，位域在本质上就是一种结构类型， 不过其成员是按二进位分配的。&nbsp;&nbsp;&nbsp;</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">二、位域的使用位域的使用和结构成员的使用相同，其一般形式为： 位域变量名&#8226;位域名 位域允许用各种格式输出。&nbsp;&nbsp;&nbsp;&nbsp;<br />main(){&nbsp;&nbsp;&nbsp;&nbsp;<br />struct bs&nbsp;&nbsp;&nbsp;&nbsp;<br />{&nbsp;&nbsp;&nbsp;&nbsp;<br />unsigned a:1;&nbsp;&nbsp;&nbsp;&nbsp;<br />unsigned b:3;&nbsp;&nbsp;&nbsp;&nbsp;<br />unsigned c:4;&nbsp;&nbsp;&nbsp;&nbsp;<br />} bit,*pbit;&nbsp;&nbsp;&nbsp;&nbsp;<br />bit.a=1;&nbsp;&nbsp;&nbsp;&nbsp;<br />bit.b=7;&nbsp;&nbsp;&nbsp;&nbsp;<br />bit.c=15;&nbsp;&nbsp;&nbsp;&nbsp;<br />pri</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">改错：<br />＃i nclude &lt;stdio.h&gt;</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">int main(void) {</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">&nbsp;&nbsp;&nbsp; int **p;<br />&nbsp;&nbsp;&nbsp; int arr[100];</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">&nbsp;&nbsp;&nbsp; p = &amp;arr;</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">&nbsp;&nbsp;&nbsp; return 0;<br />}<br />解答：<br />搞错了,是指针类型不同,<br />int **p; //二级指针<br />&amp;arr; //得到的是指向第一维为100的数组的指针<br />＃i nclude &lt;stdio.h&gt;<br />int main(void) {<br />int **p, *q;<br />int arr[100];<br />q = arr;<br />p = &amp;q;<br />return 0;<br />}</span></p><p>&nbsp;</p><p><br /><span style="color: #4822dd; ">下面这个程序执行后会有什么错误或者效果:<br />#define MAX 255<br />int main()<br />{<br />&nbsp;&nbsp; unsigned char A[MAX],i;//i被定义为unsigned char<br />&nbsp;&nbsp; for (i=0;i&lt;=MAX;i++)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; A[i]=i;<br />}<br />解答：死循环加数组越界访问（C/C++不进行数组越界检查）<br />MAX=255&nbsp;<br />数组A的下标范围为:0..MAX-1,这是其一..<br />其二.当i循环到255时,循环内执行:<br />A[255]=255;<br />这句本身没有问题..但是返回for (i=0;i&lt;=MAX;i++)语句时,<br />由于unsigned char的取值范围在(0..255),i++以后i又为0了..无限循环下去.</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">struct name1{<br />&nbsp;&nbsp; char str;<br />&nbsp;&nbsp; short x;<br />&nbsp;&nbsp; int&nbsp;&nbsp; num;<br />}</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">struct name2{<br />&nbsp;&nbsp; char str;<br />&nbsp;&nbsp; int num;<br />&nbsp;&nbsp; short x;<br />}</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">sizeof(struct name1)=8,sizeof(struct name2)=12<br />在第二个结构中，为保证num按四个字节对齐，char后必须留出3字节的空间；同时为保证整个结构的自然对齐（这里是4字节对齐），在x后还要补齐2个字节，这样就是12字节。</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">intel：<br />A.c 和B.c两个c文件中使用了两个相同名字的static变量,编译的时候会不会有问题?这两个static变量会保存到哪里（栈还是堆或者其他的）?<br />static的全局变量，表明这个变量仅在本模块中有意义，不会影响其他模块。<br />他们都放在数据区，但是编译器对他们的命名是不同的。<br />如果要使变量在其他模块也有意义的话，需要使用extern关键字。</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">struct s1<br />{<br />int i: 8;<br />int j: 4;<br />int a: 3;<br />double b;<br />};</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">struct s2<br />{<br />int i: 8;<br />int j: 4;<br />double b;<br />int a:3;<br />};</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">printf("sizeof(s1)= %d\n", sizeof(s1));<br />printf("sizeof(s2)= %d\n", sizeof(s2));<br />result: 16, 24<br />第一个struct s1<br />{<br />int i: 8;<br />int j: 4;<br />int a: 3;<br />double b;<br />};<br />理论上是这样的，首先是i在相对0的位置，占8位一个字节，然后，j就在相对一个字节的位置，由于一个位置的字节数是4位的倍数，因此不用对齐，就放在那里了，然后是a，要在3位的倍数关系的位置上，因此要移一位，在15位的位置上放下，目前总共是18位，折算过来是2字节2位的样子，由于double是8字节的，因此要在相对0要是8个字节的位置上放下，因此从18位开始到8个字节之间的位置被忽略，直接放在8字节的位置了，因此，总共是16字节。</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">第二个最后会对照是不是结构体内最大数据的倍数，不是的话，会补成是最大数据的倍数</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">上面是基本问题，接下来是编程问题：</span></p><p>&nbsp;</p><p><br /><span style="color: #4822dd; ">本人很弱，这几个题也搞不定，特来求救：<br />1）读文件file1.txt的内容（例如）：<br />12<br />34<br />56<br />输出到file2.txt：<br />56<br />34<br />12<br />（逆序）<br />2）输出和为一个给定整数的所有组合<br />例如n=5<br />5=1+4；5=2+3（相加的数不能重复）<br />则输出<br />1，4；2，3。<br />望高手赐教！！</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">第一题,注意可增长数组的应用.<br />＃i nclude &lt;stdio.h&gt;<br />＃i nclude &lt;stdlib.h&gt;</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">int main(void)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int MAX = 10;<br />int *a = (int *)malloc(MAX * sizeof(int));<br />int *b;<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />FILE *fp1;<br />FILE *fp2;</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">fp1 = fopen("a.txt","r");<br />if(fp1 == NULL)<br />{printf("error1");<br />&nbsp;&nbsp;&nbsp; exit(-1);<br />}</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">&nbsp;&nbsp;&nbsp; fp2 = fopen("b.txt","w");<br />if(fp2 == NULL)<br />{printf("error2");<br />&nbsp;&nbsp;&nbsp; exit(-1);<br />}</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">int i = 0;<br />&nbsp;&nbsp;&nbsp; int j = 0;</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">while(fscanf(fp1,"%d",&amp;a[i]) != EOF)<br />{<br />i++;<br />j++;<br />if(i &gt;= MAX)<br />{<br />MAX = 2 * MAX;<br />b = (int*)realloc(a,MAX * sizeof(int));<br />if(b == NULL)<br />{<br />printf("error3");<br />exit(-1);<br />}<br />a = b;<br />}<br />}</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">for(;--j &gt;= 0;)<br />&nbsp;&nbsp; fprintf(fp2,"%d\n",a[j]);</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">fclose(fp1);<br />fclose(fp2);</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">return 0;<br />}</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">第二题.<br />＃i nclude &lt;stdio.h&gt;</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">int main(void)<br />{<br />unsigned long int i,j,k;</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">printf("please input the number\n");<br />scanf("%d",&amp;i);<br />&nbsp;&nbsp;&nbsp; if( i % 2 == 0)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; j = i / 2;<br />else<br />j = i / 2 + 1;</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">printf("The result is \n");<br />&nbsp;&nbsp;&nbsp; for(k = 0; k &lt; j; k++)<br />&nbsp;&nbsp;&nbsp;&nbsp; printf("%d = %d + %d\n",i,k,i - k);<br />return 0;<br />}</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">＃i nclude &lt;stdio.h&gt;<br />void main()<br />{<br />unsigned long int a,i=1;<br />scanf("%d",&amp;a);<br />if(a%2==0)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp; for(i=1;i&lt;a/2;i++)<br />&nbsp;&nbsp;&nbsp;&nbsp; printf("%d",a,a-i);<br />}<br />else<br />for(i=1;i&lt;=a/2;i++)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(" %d, %d",i,a-i);<br />}</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">兄弟,这样的题目若是做不出来实在是有些不应该, 给你一个递规反向输出字符串的例子,可谓是反序的经典例程.</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">void inverse(char *p)<br />{<br />&nbsp;&nbsp;&nbsp; if( *p = = '\0' )&nbsp;<br />return;<br />&nbsp;&nbsp;&nbsp; inverse( p+1 );<br />&nbsp;&nbsp;&nbsp; printf( "%c", *p );<br />}</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">int main(int argc, char *argv[])<br />{<br />&nbsp;&nbsp;&nbsp; inverse("abc\0");</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">&nbsp;&nbsp;&nbsp; return 0;<br />}</span></p><p>&nbsp;</p><p><span style="color: #4822dd; ">借签了楼上的&#8220;递规反向输出&#8221;<br />＃i nclude &lt;stdio.h&gt;<br />void test(FILE *fread, FILE *fwrite)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char buf[1024] = {0};<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (!fgets(buf, sizeof(buf), fread))<br />}</span></p><p><span style="color: #3300ff; font-family: 楷体_GB2312; font-size: medium; "><br /></span></p><p><span style="color: #0000ff; font-family: 楷体_GB2312; font-size: medium;"><br /></span></p></div><div id="MySignature" style="margin-top: 10px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; font-size: 13px; line-height: 19px; text-align: left; background-color: #d6d3d6; "><p style="margin-bottom:0pt; margin-top:0pt; "><a href="http://www.lianzhiwei.com/"><span style=" color:#0000ff; text-decoration:underline ;font-family:'宋体'; ">奶茶加盟</span></a><a href="http://www.lianzhiwei.com/"><span style=" color:#0000ff; text-decoration:underline ;font-family:'宋体'; ">http://www.lianzhiwei.com/</span></a><span style=" font-size:10.5000pt; font-family:'宋体'; ">奶茶店加盟</span></p></div><img src ="http://www.cppblog.com/lauer3912/aggbug/170159.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2012-04-05 14:54 <a href="http://www.cppblog.com/lauer3912/archive/2012/04/05/170159.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>http://www.omgubuntu.co.uk/2011/12/ubuntu-mobile-phone-concepts/</title><link>http://www.cppblog.com/lauer3912/archive/2011/12/06/161603.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Tue, 06 Dec 2011 11:47:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/12/06/161603.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/161603.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/12/06/161603.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/161603.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/161603.html</trackback:ping><description><![CDATA[<div><a href="https://plus.google.com/u/0/105258101046165462263/posts"><img src="http://i.imgur.com/MWA6D.gif"  alt="" /></a> 				  				 				 					<h1>Ubuntu Mobile Phone Concepts</h1> 					 					<div> 						<span meta-prep-author"="">By </span> 						<span vcard"=""><a fn=""  n"="" href="http://plus.google.com/u/0/117485690627814051450/?rel=author" rel="author" title="View all posts by Joey Sneddon">Joey Sneddon</a></span>,  						<span meta-prep-entry-date"="">Published </span> 						<abbr title="2011-12-04T07:45:32+0000">December 4, 2011</abbr> 												 					</div>  					<div> 						<div>Share:</div> 						 						<div>    </div>  <div><a href="http://twitter.com/share" data-count="horizontal" data-via="omgubuntu">Tweet</a></div>  						    					</div> 					 <p><strong><a title="Ubuntu Heading to TVs, Smartphones and Tablets" href="http://www.omgubuntu.co.uk/2011/10/ubuntu-heading-to-tvs-smartphones-and-tablets/" target="_blank">Ubuntu&#8217;s plan for a multi-device&nbsp;presence</a>, to potentially include smartphones, has fired up the imagination of users.</strong></p> <p>And the community have been quick to stoke their creative talents in mocking up a variety of possible implementations.</p> <p>Below are three of those community designs that have landed in our inbox over the last week&#8230;</p> <h3>Community Designs</h3> <p><strong><em>Nick Rutledge</em></strong> mailed in with a link to his  initial designs which are more traditional in approach than some mobile  mock-ups that have been&nbsp;bandied&nbsp;around.</p> <p><a href="http://cdn.omgubuntu.co.uk/wp-content/uploads/2011/12/sdfsdf.jpg"><img size-large=""  wp-image-31776"="" title="ubuntu mobile designs" src="http://cdn.omgubuntu.co.uk/wp-content/uploads/2011/12/sdfsdf-500x266.jpg" alt="ubuntu mobile designs" height="266" width="500" /></a></p> <p><a href="http://nrutledge.blogspot.com/p/ubuntu-mobile-project.html">nrutledge.blogspot.com/p/ubuntu-mobile-project.html</a></p> <p><strong><em>Sam Horne&#8217;s</em></strong> mock-ups are &#8216;Unity-esque&#8217; in  appearance, with a strong emphasis given to familiar Unity elements such  as the launcher and a &#8216;Dash&#8217; style search &#8211; both of which are played to  great use on his&nbsp;home-screen design in particular.</p> <p><img src="http://th07.deviantart.net/fs70/PRE/f/2011/317/b/b/ubuntu_with_mobile_unity_by_ginjaninja405-d4g2ok7.png" alt="" width="500" /></p> <p>&#8220;I would like to share with you my own Ubuntu for mobile phones  mock-up, just as a way of giving my two cents.&#8221; Sam told us when mailing  in his designs.</p> <p>&#8220;I gave the design some real thought (even if it&#8217;s not a perfect  mock-up) to truly show how I&#8217;d make the mobile OS. Getting the design  right is a big deal in my head, so I used my own HTC Desire to look at  &nbsp;them every time I made a change, just to make sure it felt natural or  doable on an actual smartphone.&#8221;</p> <p><a href="http://ginjaninja405.deviantart.com/art/Ubuntu-with-mobile-Unity-268863703">ginjaninja405.deviantart.com/art/Ubuntu-with-mobile-Unity-268863703</a></p> <p>Serial designer&nbsp;<strong><em>Musl1m </em></strong>took to his&nbsp;DeviantArt with a well thought out, and very Faenza styled, design.</p> <p>I love the approach to app navigation, particularly in his &#8216;Ubuntu Software Centre&#8217; design.</p> <p><a href="http://fc03.deviantart.net/fs71/f/2011/331/e/4/ubuntu_phone_explained_by_musl1m-d4hhe04.png"><img src="http://fc03.deviantart.net/fs71/f/2011/331/e/4/ubuntu_phone_explained_by_musl1m-d4hhe04.png" alt="" width="500" /></a></p> <p><a href="http://musl1m.deviantart.com/art/Ubuntu-Phone-Explained-271229476">musl1m.deviantart.com/art/Ubuntu-Phone-Explained-271229476</a></p> <p>&nbsp;</p></div><img src ="http://www.cppblog.com/lauer3912/aggbug/161603.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-12-06 19:47 <a href="http://www.cppblog.com/lauer3912/archive/2011/12/06/161603.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>WikiSyntax   (来源Google)</title><link>http://www.cppblog.com/lauer3912/archive/2011/11/09/159848.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Tue, 08 Nov 2011 22:52:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/11/09/159848.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/159848.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/11/09/159848.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/159848.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/159848.html</trackback:ping><description><![CDATA[<div><table><tbody><tr><td style="vertical-align:top; padding-left:5px"><div id="wikiheader"><div>     <em>The reference to the wiki syntax for Google Code projects</em>      <br />    <a style="padding-top: 2px" href="http://code.google.com/p/support/w/list?q=label:Restrict-AddWikiComment-Commit" title="Restrict-AddWikiComment-Commit">Restrict-AddWikiComment-Commit</a>        <div id="wikiauthor" style="float:right">  Updated <span title="Wed Aug 17 15:10:16 2011">  Aug 17, 2011</span>    by <a style="white-space: nowrap" href="http://code.google.com/u/dbentley@google.com/">dbentley@google.com</a>    </div>  </div>  </div>    <div id="wikicontent">  <div id="wikimaincol">  <h1><a name="Wiki_Syntax"></a>Wiki Syntax</h1><ul><li><a href="http://code.google.com/p/support/wiki/WikiSyntax#Wiki_Syntax">Wiki Syntax</a></li><li><a href="http://code.google.com/p/support/wiki/WikiSyntax#Introduction">Introduction</a></li><li><a href="http://code.google.com/p/support/wiki/WikiSyntax#Pragmas">Pragmas</a></li><li><a href="http://code.google.com/p/support/wiki/WikiSyntax#Wiki-style_markup">Wiki-style markup</a></li><ul><li><a href="http://code.google.com/p/support/wiki/WikiSyntax#Paragraphs">Paragraphs</a></li><li><a href="http://code.google.com/p/support/wiki/WikiSyntax#Typeface">Typeface</a></li><li><a href="http://code.google.com/p/support/wiki/WikiSyntax#Code">Code</a></li><li><a href="http://code.google.com/p/support/wiki/WikiSyntax#Headings">Headings</a></li><li><a href="http://code.google.com/p/support/wiki/WikiSyntax#Dividers">Dividers</a></li><li><a href="http://code.google.com/p/support/wiki/WikiSyntax#Lists">Lists</a></li><li><a href="http://code.google.com/p/support/wiki/WikiSyntax#Quoting">Quoting</a></li><li><a href="http://code.google.com/p/support/wiki/WikiSyntax#Links">Links</a></li><li><a href="http://code.google.com/p/support/wiki/WikiSyntax#Tables">Tables</a></li></ul><li><a href="http://code.google.com/p/support/wiki/WikiSyntax#HTML_support">HTML support</a></li><ul><li><a href="http://code.google.com/p/support/wiki/WikiSyntax#Escaping_HTML_Tags">Escaping HTML Tags</a></li></ul><li><a href="http://code.google.com/p/support/wiki/WikiSyntax#Comments">Comments</a></li><li><a href="http://code.google.com/p/support/wiki/WikiSyntax#+1_Button">+1 Button</a></li><li><a href="http://code.google.com/p/support/wiki/WikiSyntax#Gadgets">Gadgets</a></li><li><a href="http://code.google.com/p/support/wiki/WikiSyntax#Videos">Videos</a></li><li><a href="http://code.google.com/p/support/wiki/WikiSyntax#Navigation">Navigation</a></li><ul><li><a href="http://code.google.com/p/support/wiki/WikiSyntax#Table_of_Contents">Table of Contents</a></li><li><a href="http://code.google.com/p/support/wiki/WikiSyntax#Side_navigation">Side navigation</a></li></ul><li><a href="http://code.google.com/p/support/wiki/WikiSyntax#Localizing_Wiki_Content">Localizing Wiki Content</a></li></ul>  <h1><a name="Introduction"></a>Introduction</h1><p>Each  wiki page is stored in a .wiki file under the /wiki directory in a  project's repository.  Each file's name is the same as the wiki page  name.  And, each wiki file consists of optional pragma lines followed by  the content of the page. </p><h1><a name="Pragmas"></a>Pragmas</h1><p>Optional  pragma lines provide metadata about the page and how it should be  displayed. These lines are only processed if they appear at the top of  the file.  Each pragma line begins with a pound-sign (#) and the pragma  name, followed by a value. </p><table><tbody><tr><td style="border: 1px solid #ccc; padding: 5px;"> <strong>Pragma</strong>   </td><td style="border: 1px solid #ccc; padding: 5px;"> <strong>Value</strong>  </td></tr> <tr><td style="border: 1px solid #ccc; padding: 5px;"> #summary   </td><td style="border: 1px solid #ccc; padding: 5px;"> One-line summary of the page </td></tr> <tr><td style="border: 1px solid #ccc; padding: 5px;"> #labels    </td><td style="border: 1px solid #ccc; padding: 5px;"> Comma-separated list of labels (filled in automatically via the web UI) </td></tr> <tr><td style="border: 1px solid #ccc; padding: 5px;"> #sidebar   </td><td style="border: 1px solid #ccc; padding: 5px;"> See <a href="http://code.google.com/p/support/wiki/WikiSyntax#Side_navigation" rel="nofollow">Side navigation</a> </td></tr> </tbody></table><h1><a name="Wiki-style_markup"></a>Wiki-style markup</h1><h2><a name="Paragraphs"></a>Paragraphs</h2><p>Use one or more blank lines to separate paragraphs.  </p><h2><a name="Typeface"></a>Typeface</h2><table><tbody><tr><td style="border: 1px solid #ccc; padding: 5px;"> Name/Sample</td><td style="border: 1px solid #ccc; padding: 5px;"> <strong> Markup </strong>       </td></tr> <tr><td style="border: 1px solid #ccc; padding: 5px;">  <em>italic</em>       </td><td style="border: 1px solid #ccc; padding: 5px;"> <tt>_italic_</tt>       </td></tr> <tr><td style="border: 1px solid #ccc; padding: 5px;">  <strong>bold</strong>         </td><td style="border: 1px solid #ccc; padding: 5px;"> <tt>*bold*</tt>         </td></tr> <tr><td style="border: 1px solid #ccc; padding: 5px;">  <tt>code</tt>         </td><td style="border: 1px solid #ccc; padding: 5px;"> <tt>`code`</tt>     </td></tr> <tr><td style="border: 1px solid #ccc; padding: 5px;">  <tt>code</tt>     </td><td style="border: 1px solid #ccc; padding: 5px;"> <tt>{{{code}}}</tt>     </td></tr> <tr><td style="border: 1px solid #ccc; padding: 5px;">  <sup>super</sup>script  </td><td style="border: 1px solid #ccc; padding: 5px;"> <tt>^super^script</tt>  </td></tr> <tr><td style="border: 1px solid #ccc; padding: 5px;">  <sub>sub</sub>script  </td><td style="border: 1px solid #ccc; padding: 5px;"> <tt>,,sub,,script</tt>  </td></tr> <tr><td style="border: 1px solid #ccc; padding: 5px;"> <span style="text-decoration: line-through">strikeout</span>   </td><td style="border: 1px solid #ccc; padding: 5px;"> <tt>~~strikeout~~</tt>  </td></tr> </tbody></table><p>You can mix these typefaces in some ways: </p><table><tbody><tr><td style="border: 1px solid #ccc; padding: 5px;">       <strong>Markup</strong>                    </td><td style="border: 1px solid #ccc; padding: 5px;">        <strong>Result</strong>                 </td></tr> <tr><td style="border: 1px solid #ccc; padding: 5px;"> <tt>_*bold* in italics_</tt>             </td><td style="border: 1px solid #ccc; padding: 5px;"> <em><strong>bold</strong> in italics</em>             </td></tr> <tr><td style="border: 1px solid #ccc; padding: 5px;"> <tt>*_italics_ in bold*</tt>             </td><td style="border: 1px solid #ccc; padding: 5px;"> <strong><em>italics</em> in bold</strong>             </td></tr> <tr><td style="border: 1px solid #ccc; padding: 5px;"> <tt>*~~strike~~ works too*</tt>          </td><td style="border: 1px solid #ccc; padding: 5px;"> <strong><span style="text-decoration: line-through">strike</span> works too</strong>          </td></tr> <tr><td style="border: 1px solid #ccc; padding: 5px;"> <tt>~~as well as _this_ way round~~</tt> </td><td style="border: 1px solid #ccc; padding: 5px;"> <span style="text-decoration: line-through">as well as <em>this</em> way round</span> </td></tr> </tbody></table><h2><a name="Code"></a>Code</h2><p>If you have a multiline code block that you want to display verbatim, use the multiline code delimiter: </p><pre>{{{<br />def fib(n):<br />&nbsp; if n == 0 or n == 1:<br />&nbsp; &nbsp; return n<br />&nbsp; else:<br />&nbsp; &nbsp; # This recursion is not good for large numbers.<br />&nbsp; &nbsp; return fib(n-1) + fib(n-2)<br />}}}</pre><p>Which results in: </p><pre>def fib(n):<br />&nbsp; if n == 0 or n == 1:<br />&nbsp; &nbsp; return n<br />&nbsp; else:<br />&nbsp; &nbsp; # This recursion is not good for large numbers.<br />&nbsp; &nbsp; return fib(n-1) + fib(n-2)</pre><p>For more control over the syntax higlighting, the <tt>&lt;code&gt;</tt> tag allows you to specify a file extension: </p><pre>&lt;code language="xml"&gt;<br />&lt;hello target="world"/&gt;<br />&lt;/code&gt;</pre><p>To disable highlighting entirely, use the <tt>&lt;pre&gt;</tt> tag. </p><h2><a name="Headings"></a>Headings</h2><pre>= Heading =<br />== Subheading ==<br />=== Level 3 ===<br />==== Level 4 ====<br />===== Level 5 =====<br />====== Level 6 ======</pre><h2><a name="Dividers"></a>Dividers</h2><p>Four or more dashes on a line by themselves results in a horizontal rule. </p><h2><a name="Lists"></a>Lists</h2><p>Google  Code wikis support both bulleted and numbered lists. A list must be  indented at least one space to be recognized as such. You can also nest  lists one within the other by appropriate use of indenting: </p><pre>The following is:<br />&nbsp; * A list<br />&nbsp; * Of bulleted items<br />&nbsp; &nbsp; # This is a numbered sublist<br />&nbsp; &nbsp; # Which is done by indenting further<br />&nbsp; * And back to the main bulleted list<br /><br />&nbsp;* This is also a list<br />&nbsp;* With a single leading space<br />&nbsp;* Notice that it is rendered<br />&nbsp; # At the same levels<br />&nbsp; # As the above lists.<br />&nbsp;* Despite the different indentation levels.</pre><p>The following is: </p><ul><li>A list </li><li>Of bulleted items </li><ol><li>This is a numbered sublist </li><li>Which is done by indenting further </li></ol><li>And back to the main bulleted list </li></ul><ul><li>This is also a list </li><li>With a single leading space </li><li>Notice that it is rendered </li><ol><li>At the same levels </li><li>As the above lists. </li></ol><li>Despite the different indentation levels. </li></ul><h2><a name="Quoting"></a>Quoting</h2><p>Block  quotes place emphasis on a particular extract of text in your page.  Block quotes are created by indenting a paragraph by at least one space:  </p><pre>Someone once said:<br /><br />&nbsp; This sentence will be quoted in the future as the canonical example<br />&nbsp; of a quote that is so important that it should be visually separate<br />&nbsp; from the rest of the text in which it appears.</pre><p>Someone once said: </p><blockquote>This sentence will be quoted in the future as the canonical example  of a quote that is so important that it should be visually separate  from the rest of the text in which it appears.  </blockquote><h2><a name="Links"></a>Links</h2><p>Links are central to  the wiki principle, as they create the web of content. Google Code wiki  permits both internal (within the wiki) and external links, and in some  cases automatically creates a link when it recognizes either a WikiWord  or an URL. </p><h3><a name="Internal_wiki_links"></a>Internal wiki links</h3><p>Internal  links within a wiki are created using the syntax below. If you add a  wiki link to a page that does not exist, the link will appear with a  LittleLink<a href="http://code.google.com/p/support/wiki/WikiSyntax">?</a>  to project committers and owners. Clicking that link will take you to  the page creation form where you can enter content for that page. </p><p>If  you are not logged in, wiki links that point to non-existent pages will  appear as plain text, without the link to the page creation form. When  you create the target page, the link will become a normal hyperlink for  all viewers of the page. </p><pre>WikiSyntax is identified and linked automatically<br /><br />Wikipage is not identified, so if you have a page named [Wikipage] you<br />need to link it explicitly.<br /><br />If the WikiSyntax page is actually about reindeers, you can provide a<br />description, so that people know you are actually linking to a page on<br />[WikiSyntax reindeer flotillas].<br /><br />If you want to mention !WikiSyntax without it being autolinked, use an<br />exclamation mark to prevent linking.</pre><p><a href="http://code.google.com/p/support/wiki/WikiSyntax">WikiSyntax</a> is identified and linked automatically </p><p>Wikipage is not identified, so if you have a page named Wikipage you need to link it explicitly. </p><p>If the <a href="http://code.google.com/p/support/wiki/WikiSyntax">WikiSyntax</a> page is actually about reindeers, you can provide a description, so that people know you are actually linking to a page on <a href="http://code.google.com/p/support/wiki/WikiSyntax">reindeer flotillas</a>. </p><p>If you want to mention WikiSyntax without it being autolinked, use an exclamation mark to prevent linking. </p><h3><a name="Links_to_anchors_within_a_page"></a>Links to anchors within a page</h3><p>Each  heading defines a HTML anchor with the same name as the heading, but  with spaces replaced by underscores. You can create a link to a specific  heading on a page like this: </p><pre>[WikiSyntax#Wiki-style_markup]</pre><p>And it will render as: <a href="http://code.google.com/p/support/wiki/WikiSyntax#Wiki-style_markup">WikiSyntax#Wiki-style_markup</a>. </p><h3><a name="Links_to_issues_and_revisions"></a>Links to issues and revisions</h3><p>You can easily link to issues and revisions using the following syntax. </p><ul><li><tt>issue 123</tt> will be autolinked to issue number 123 in the current project.  You can include a <tt>#</tt>  or not.  If the issue has been closed, the link will appear as a  cross-out rather than an underline.  Hovering your mouse over such a  link shows the issue summary. </li></ul><ul><li><tt>issue PROJECTNAME:122</tt>  will be autolinked to that issue number in the specified project.  This  is useful when your project depends on work being done in related  projects. </li></ul><ul><li><tt>r123</tt> will be autolinked to the revision detail page for that revision in the current project. </li></ul><p>There is currently no way to disable this type of autolinking. See <a title="Disable autolinking to revisions when ! is used" href="http://code.google.com/p/support/issues/detail?id=996">issue 996</a>. </p><pre>For example: Please add a comment on issue 123 rather than adding more review comments to r456. </pre><p>Renders as: Please add a comment on <a title="images and internal wiki links" href="http://code.google.com/p/support/issues/detail?id=123">&nbsp;issue 123&nbsp;</a> rather than adding more review comments to <a href="http://code.google.com/p/support/source/detail?r=456">r456</a>. </p><h3><a name="Links_to_external_pages"></a>Links to external pages</h3><p>You can of course link to external pages from your own wiki pages, using a syntax similar to that for internal links: </p><pre>Plain URLs such as http://www.google.com/ or ftp://ftp.kernel.org/ are<br />automatically made into links.<br /><br />You can also provide some descriptive text. For example, the following<br />link points to the [http://www.google.com Google home page].<br /><br />If your link points to an image, it will get inserted as an image tag<br />into the page:<br /><br />http://code.google.com/images/code_sm.png<br /><br />You can also make the image into a link, by setting the image URL as<br />the description of the URL you want to link:<br /><br />[http://code.google.com/ http://code.google.com/images/code_sm.png]</pre><p>Plain URLs such as <a href="http://www.google.com/" rel="nofollow">http://www.google.com/</a> or <a href="ftp://ftp.kernel.org/" rel="nofollow">ftp://ftp.kernel.org/</a> are automatically made into links. </p><p>You can also provide some descriptive text. For example, the following link points to the <a href="http://www.google.com/" rel="nofollow">Google home page</a>. </p><p>You can also make the image into a link, by setting the image URL as the description of the URL you want to link: </p><pre>[http://code.google.com/ http://code.google.com/images/code_sm.png]</pre><p><a href="http://code.google.com/" rel="nofollow"><img src="http://code.google.com/images/code_sm.png"  alt="" /></a> </p><h3><a name="Links_to_images"></a>Links to images</h3><p>If your link points to an image (that is, if it ends in <tt>.png</tt>, <tt>.gif</tt>, <tt>.jpg</tt> or <tt>.jpeg</tt>), it will get inserted as an image into the page: </p><pre>http://code.google.com/images/code_sm.png</pre><p><img src="http://code.google.com/images/code_sm.png"  alt="" /> </p><p>If  the image is produced by a server-side script, you may need to add a  nonsense query string parameter to the end so that the URL ends with a  supported image filename extension. </p><pre>http://chart.apis.google.com/chart?chs=200x125&amp;chd=t:48.14,33.79,19.77|83.18,18.73,12.04&amp;cht=bvg&amp;nonsense=something_that_ends_with.png</pre><p><img src="http://chart.apis.google.com/chart?chs=200x125&amp;chd=t:48.14,33.79,19.77%7C83.18,18.73,12.04&amp;cht=bvg&amp;nonsense=something_that_ends_with.png"  alt="" /> </p><h2><a name="Tables"></a>Tables</h2><p>Tables are created by entering the content of each cell separated by <tt>||</tt> delimiters. You can insert other inline wiki syntax in table cells, including typeface formatting and links. </p><pre>|| *Year* || *Temperature (low)* || *Temperature (high)* ||<br />|| 1900 || -10 || 25 ||<br />|| 1910 || -15 || 30 ||<br />|| 1920 || -10 || 32 ||<br />|| 1930 || _N/A_ || _N/A_ ||<br />|| 1940 || -2 || 40 ||</pre><table><tbody><tr><td style="border: 1px solid #ccc; padding: 5px;"> <strong>Year</strong> </td><td style="border: 1px solid #ccc; padding: 5px;"> <strong>Temperature (low)</strong> </td><td style="border: 1px solid #ccc; padding: 5px;"> <strong>Temperature (high)</strong> </td></tr> <tr><td style="border: 1px solid #ccc; padding: 5px;"> 1900 </td><td style="border: 1px solid #ccc; padding: 5px;"> -10 </td><td style="border: 1px solid #ccc; padding: 5px;"> 25 </td></tr> <tr><td style="border: 1px solid #ccc; padding: 5px;"> 1910 </td><td style="border: 1px solid #ccc; padding: 5px;"> -15 </td><td style="border: 1px solid #ccc; padding: 5px;"> 30 </td></tr> <tr><td style="border: 1px solid #ccc; padding: 5px;"> 1920 </td><td style="border: 1px solid #ccc; padding: 5px;"> -10 </td><td style="border: 1px solid #ccc; padding: 5px;"> 32 </td></tr> <tr><td style="border: 1px solid #ccc; padding: 5px;"> 1930 </td><td style="border: 1px solid #ccc; padding: 5px;"> <em>N/A</em> </td><td style="border: 1px solid #ccc; padding: 5px;"> <em>N/A</em> </td></tr> <tr><td style="border: 1px solid #ccc; padding: 5px;"> 1940 </td><td style="border: 1px solid #ccc; padding: 5px;"> -2 </td><td style="border: 1px solid #ccc; padding: 5px;"> 40 </td></tr> </tbody></table><h1><a name="HTML_support"></a>HTML support</h1><p>To  aid in the presentation of a wiki page there is some support for HTML.  HTML tags are only supported in wiki pages, not in page comments. </p><p>HTML syntax can be used in conjunction with wiki syntax, but it is recommended against doing so where possible. </p><p>The following HTML tags and attributes are currently supported: </p><table border="1"> <thead><tr><th>HTML Tag</th><th>Supported Attributes</th></tr></thead> <tbody> <tr><td>a</td><td>title dir lang href</td></tr> <tr><td>b</td><td>title dir lang</td></tr> <tr><td>br</td><td>title dir lang</td></tr> <tr><td>blockquote</td><td>title dir lang</td></tr> <tr><td>code</td><td>title dir lang language <tt>[1]</tt></td></tr>       <tr><td>dd</td><td>title dir lang</td></tr> <tr><td>div</td><td>title dir lang</td></tr> <tr><td>dl</td><td>title dir lang</td></tr>       <tr><td>dt</td><td>title dir lang</td></tr>       <tr><td>em</td><td>title dir lang</td></tr>       <tr><td>font</td><td>title dir lang face size color</td></tr>       <tr><td>h1</td><td>title dir lang</td></tr>       <tr><td>h2</td><td>title dir lang</td></tr>       <tr><td>h3</td><td>title dir lang</td></tr>       <tr><td>h4</td><td>title dir lang</td></tr>       <tr><td>h5</td><td>title dir lang</td></tr>       <tr><td>i</td><td>title dir lang</td></tr>       <tr><td>img</td><td>title dir lang src alt border height width align</td></tr>   <tr><td>li</td><td>title dir lang</td></tr>       <tr><td>ol</td><td>title dir lang type start</td></tr>     <tr><td>p</td><td>title dir lang align</td></tr>      <tr><td>pre</td><td>title dir lang</td></tr>       <tr><td>q</td><td>title dir lang</td></tr>       <tr><td>s</td><td>title dir lang</td></tr>       <tr><td>span</td><td>title dir lang</td></tr>      <tr><td>strike</td><td>title dir lang</td></tr>      <tr><td>strong</td><td>title dir lang</td></tr>       <tr><td>sub</td><td>title dir lang</td></tr>       <tr><td>sup</td><td>title dir lang</td></tr>   <tr><td>table</td><td>title dir lang align valign cellspacing cellpadding border width height</td></tr>   <tr><td>tbody</td><td>title dir lang align valign cellspacing cellpadding border width height</td></tr>   <tr><td>td</td><td>title dir lang align valign cellspacing cellpadding border width height</td></tr>   <tr><td>tfoot</td><td>title dir lang align valign cellspacing cellpadding border width height</td></tr>   <tr><td>th</td><td>title dir lang align valign cellspacing cellpadding border width height</td></tr>   <tr><td>thead</td><td>title dir lang align valign cellspacing cellpadding border width height colspan rowspan</td></tr> <tr><td>tr</td><td>title dir lang align valign cellspacing cellpadding border width height colspan rowspan</td></tr> <tr><td>tt</td><td>title dir lang</td></tr>       <tr><td>u</td><td>title dir lang</td></tr>       <tr><td>ul</td><td>title dir lang type</td></tr>      <tr><td>var</td><td>title dir lang</td></tr>      </tbody> </table> <p><tt>[1]</tt>  The language attribute of the code tag is the file extension of the  language used in the code block. It is used as a hint for the syntax  highlighter. </p><h2><a name="Escaping_HTML_Tags"></a>Escaping HTML Tags</h2><p>When you want to display html tags directly on your wiki page (as opposed to rendered), you will need to escape each HTML tag.  </p><p>HTML tags can be escaped as shown in the table below: </p><table border="1"> <thead><tr><th>Markup</th><th>Result</th></tr></thead> <tbody> <tr><td> <tt>`&lt;hr&gt;`</tt></td><td><tt>&lt;hr&gt;</tt></td></tr> <tr><td> <tt>{{{&lt;hr&gt;}}}</tt></td><td><tt>&lt;hr&gt;</tt></td></tr> </tbody> </table> <p><br /><br /> </p><h1><a name="Comments"></a>Comments</h1><p>The  wiki supports embedded comments to help explain the contents of a wiki  page. Anything inside the comment block is removed from the rendered  page, but is visible when editing or viewing the source for that page. </p><pre>&lt;wiki:comment&gt;<br />This text will be removed from the rendered page.<br />&lt;/wiki:comment&gt;</pre><h1><a name="+1_Button"></a>+1 Button</h1><p>Use <tt>&lt;g:plusone&gt;&lt;/g:plusone&gt;</tt> to add a <a href="http://www.google.com/+1/button/" rel="nofollow">+1 button</a> to the page. Example: </p><pre>&lt;g:plusone size="medium"&gt;&lt;/g:plusone&gt;</pre> <p>The count, size, and href parameters are supported; see <a href="http://code.google.com/apis/+1button/" rel="nofollow">http://code.google.com/apis/+1button/</a> for documentation. </p><h1><a name="Gadgets"></a>Gadgets</h1><p>You can embed <a href="http://www.google.com/webmasters/gadgets/" rel="nofollow">Gadgets</a> on your wiki pages with the following syntax: </p><pre>&lt;wiki:gadget url="http://example.com/gadget.xml" height="200" border="0" /&gt; </pre><p>Valid attributes are: </p><ul><li><tt>url</tt>: the URL of the gadget </li><li><tt>width</tt>: the width of the gadget </li><li><tt>height</tt>: the height of the gadget </li><li><tt>title</tt>: a title to display above the gadget </li><li><tt>border</tt>: "0" or "1", whether to draw a border around the gadget </li><li><tt>up_*</tt>: Gadget user preference parameters </li><li><tt>caja</tt>: "0" or "1", whether to use Caja to render the gadget.  <a href="http://code.google.com/p/google-caja" rel="nofollow">Caja</a> helps protect users from malicious or accidental errors in third party gadgets. </li></ul><p><a href="http://code.google.com/p/support/wiki/WorkingWithGoogleGadgets">WorkingWithGoogleGadgets</a>  describes how to create gadgets for Google Code. It also provides  a  few helpful suggestions that can make it easier to publish gadgets and  to integrate with other Google products such as iGoogle. </p><p><a href="http://code.google.com/p/support/wiki/InterestingDeveloperGadgets">InterestingDeveloperGadgets</a> shows some sample gadgets you may want to include on your project pages. </p><h1><a name="Videos"></a>Videos</h1><p>You can embed videos with the following syntax: </p><pre>&lt;wiki:video url="http://www.youtube.com/watch?v=3LkNlTNHZzE"/&gt;</pre><p>Valid attributes are: </p><ul><li><tt>url</tt>: the URL of the video </li><li><tt>width</tt>: the width of the embedded video </li><li><tt>height</tt>: the height of the embedded video </li></ul><p>Right now we support videos from Youtube and Google Video, but other containers can be added to our <a href="http://code.google.com/p/google-code-project-hosting-gadgets/source/browse/#svn/trunk/video" rel="nofollow">open source gadgets project</a>. </p><h1><a name="Navigation"></a>Navigation</h1><h2><a name="Table_of_Contents"></a>Table of Contents</h2><p>An  inline table of contents can be generated from page headers on a wiki  page. Add the following syntax to a page in the location the table of  contents should be displayed: </p><pre>&lt;wiki:toc max_depth="1" /&gt;</pre><p>Valid attributes are: </p><ul><li><tt>max_depth</tt>: the maximum header depth to display in the table of contents </li></ul><h2><a name="Side_navigation"></a>Side navigation</h2><p>You can specify the sidebar for a wiki page by selecting another wiki page that defines your side navigation. The <a href="http://code.google.com/p/doctype/wiki/Articles" rel="nofollow">doctype project</a> uses the sidebar extensively across its wiki. </p><p>One  way of adding a sidebar is by setting the #sidebar pragma, as shown  below. Alternatively, the sidebar pragma can be left blank if no side  navigation is desired.  </p><table><tbody><tr><td style="border: 1px solid #ccc; padding: 5px;"> #sidebar TableOfContents </td></tr> </tbody></table><p>The side navigation that is defined should be in the format of a simple list, as shown below.  </p><pre>&nbsp;* [Articles HOWTO articles]<br />&nbsp; &nbsp; * [ArticlesXSS Web security]<br />&nbsp; &nbsp; * [ArticlesDom DOM manipulation]<br />&nbsp; &nbsp; * [ArticlesStyle CSS and style]<br />&nbsp; &nbsp; * [ArticlesTips Tips and tricks]<br />&nbsp; * [DOMReference DOM reference]<br />&nbsp; * [HTMLElements HTML reference]<br />&nbsp; * [CSSReference CSS reference]</pre><p>A  default sidebar page can also be specified for all wiki pages by  project owners through the Wiki settings in the Administer tab. If a  #sidebar pragma is also specified, it will take precedence on the page. </p><h1><a name="Localizing_Wiki_Content"></a>Localizing Wiki Content</h1><p>Along  with the default language for the wiki, which can be set through the  Wiki settings in the Administer tab, additional languages are also  supported. If more than one language is available, based on a user's  language preference (e.g. browser language), the wiki will try to serve  the page for the appropriate language. If no wiki page exists for that  language, it will fall back to the default language. Comments, however,  are shared amongst all translations of a wiki page. </p><p>New translations for a page cannot be added through the web interface and have to be added through the Subversion repository.  </p><p>To add a translation of a page, first checkout the wiki from Subversion: <br /><br /> <tt>svn checkout https://</tt><strong>yourproject</strong><tt>.googlecode.com/svn/wiki/</tt> <strong>yourdirectory</strong> <tt>-username</tt> <strong>yourusername</strong> </p><p>Then  create a new directory under /wiki/ using the two letter ISO-639 code  as the name of that directory. Place all translated files in the new  directory and submit those changes to the Subversion repository.  </p><p>The following is an example of a valid wiki directory: </p><pre>wiki/<br />&nbsp; &nbsp;ja/<br />&nbsp; &nbsp; &nbsp; ProjectHistory.wiki<br />&nbsp; &nbsp; &nbsp; StyleGuide.wiki<br />&nbsp; &nbsp;zh-Hans/<br />&nbsp; &nbsp; &nbsp; ProjectHistory.wiki<br />&nbsp; &nbsp; &nbsp; StyleGuide.wiki<br />&nbsp; &nbsp;zh-Hant/<br />&nbsp; &nbsp; &nbsp; ProjectHistory.wiki<br />&nbsp; &nbsp; &nbsp; StyleGuide.wiki<br />&nbsp; &nbsp;ProjectHistory.wiki<br />&nbsp; &nbsp;StyleGuide.wiki</pre><p>Once  the files been be submitted to the project's subversion repository,  they can now be edited through the wiki's web editor. The process is the  same for Mercurial or Git projects, except that the wiki lives in the  root directory (not wiki/) of <tt>https://wiki.</tt><strong>yourproject</strong><tt>.googlecode.com/hg/</tt> or <tt>https://wiki.</tt><strong>yourproject</strong><tt>.googlecode.com/git/</tt>. </p><p>Note:  The wiki accepts a subset of ISO-639 two letter language codes, where a  few of the codes (such as zh_Hans) contain locale-specific codes. Such  locale-specific codes should use a hyphen (zh-Hans) separator. A few  example language codes have been specified in the table below. </p><table border="1"> <tbody><tr> <th> Language (Locale)</th> <th> Directory Name </th> </tr> <tr> <td>Arabic</td> <td>ar</td> </tr> <tr> <td>Bulgarian</td> <td>bg</td> </tr> <tr> <td>Chinese (China)</td> <td>zh-Hans</td> </tr> <tr> <td>Chinese (Taiwan)</td> <td>zh-Hant</td> </tr> <tr> <td>Croatian</td> <td>hr</td> </tr> <tr> <td>Czech</td> <td>cs</td> </tr> <tr> <td>Danish</td> <td>da</td> </tr> <tr> <td>Dutch</td> <td>nl</td> </tr> <tr> <td>English (United Kingdom)</td> <td>en-GB</td> </tr> <tr> <td>English (United States)</td> <td>en-US</td> </tr> <tr> <td>Finnish</td> <td>fi</td> </tr> <tr> <td>French</td> <td>fr</td> </tr> <tr> <td>German</td> <td>de</td> </tr> <tr> <td>Greek</td> <td>el</td> </tr> <tr> <td>Hebrew</td> <td>he</td> </tr> <tr> <td>Hungarian</td> <td>hu</td> </tr> <tr> <td>Italian</td> <td>it</td> </tr> <tr> <td>Japanese</td> <td>ja</td> </tr> <tr> <td>Korean</td> <td>ko</td> </tr> <tr> <td>Norwegian</td> <td>no</td> </tr> <tr> <td>Polish</td> <td>pl</td> </tr> <tr> <td>Portuguese (Brazil)</td> <td>pt-BR</td> </tr> <tr> <td>Romanian</td> <td>ro</td> </tr> <tr> <td>Russian</td> <td>ru</td> </tr> <tr> <td>Slovak</td> <td>sk</td> </tr> <tr> <td>Spanish</td> <td>es</td> </tr> <tr> <td>Swedish</td> <td>sv</td> </tr> <tr> <td>Turkish</td> <td>tr</td> </tr> </tbody></table> <p><em>The content on this page created by Google is licensed under the <a href="http://creativecommons.org/licenses/by/3.0/" rel="nofollow">Creative Commons Attribution 3.0 License</a>.  User-generated content is not included in this license.</em> </p>  </div>  </div>  </td></tr><tr> </tr></tbody></table></div><img src ="http://www.cppblog.com/lauer3912/aggbug/159848.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-11-09 06:52 <a href="http://www.cppblog.com/lauer3912/archive/2011/11/09/159848.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Google推出JavaScript测试工具Google JS Test</title><link>http://www.cppblog.com/lauer3912/archive/2011/10/08/157824.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Sat, 08 Oct 2011 14:04:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/10/08/157824.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/157824.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/10/08/157824.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/157824.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/157824.html</trackback:ping><description><![CDATA[<span style="color: #333333; font-family: 宋体; line-height: 18px; "><div bgf8f8f8"="" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; width: 597px; padding-top: 12px; padding-right: 18px; padding-left: 18px; margin-top: 10px; border-top-color: #d8d9d9; border-right-color: #d8d9d9; border-left-color: #d8d9d9; border-top-width: 1px; border-right-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-left-style: solid; border-bottom-style: none; border-bottom-width: initial; border-bottom-color: initial; "><div style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-top-color: #73a0cf; border-right-color: #73a0cf; border-bottom-color: #73a0cf; border-left-color: #73a0cf; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dashed; border-right-style: dashed; border-bottom-style: dashed; border-left-style: dashed; line-height: 26px; padding-top: 8px; padding-right: 12px; padding-bottom: 8px; padding-left: 12px; background-position: initial initial; background-repeat: initial initial; "><p green"="" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #006600; background-color: transparent; font-size: 14px; ">Google JS Test是一个运行于V8 JavaScript引擎下的JavaScript单元测试框架，其在Google内部负责对Chrome的快速JS执行速度进行测试，现在Google以开源工程开放给大家使用。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #333333; background-color: transparent; text-align: right; ">AD：</p></div></div><div bgf8f8f8=""  f14"="" style="font-size: 14px; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; padding-top: 12px; padding-right: 18px; padding-left: 18px; line-height: 28px; margin-bottom: 10px; position: relative; min-height: 500px; "><div id="content"><p style="margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #333333; background-color: transparent; text-indent: 28px; "></p><p style="margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #333333; background-color: transparent; text-indent: 28px; "><a target="_blank" href="http://code.google.com/p/google-js-test/" style="color: #004276; text-decoration: underline; ">Google JS Test</a>是一个运行于V8 JavaScript引擎下的JavaScript单元测试框架，其在Google内部负责对Chrome的快速JS执行速度进行测试，现在Google以开源工程开放给大家使用。</p><p style="margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #333333; background-color: transparent; text-indent: 28px; "></p><center><img alt="" src="http://images.51cto.com/files/uploadimg/20111008/1348130.jpg" width="28" height="30" style="border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-style: initial; border-color: initial; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; width: 334px; height: 363px; " /></center><p style="margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #333333; background-color: transparent; text-indent: 28px; "></p><p style="margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #333333; background-color: transparent; text-indent: 28px; "><strong style="font-weight: bold; text-align: center; ">Google JS Test主要特性：</strong></p><p style="margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #333333; background-color: transparent; text-indent: 28px; ">&#9670; 超快的启动速度和执行时间，不需要在浏览器里运行</p><p style="margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #333333; background-color: transparent; text-indent: 28px; ">&#9670; 清爽而具有可读性的输出内容</p><p style="margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #333333; background-color: transparent; text-indent: 28px; ">&#9670; 也有一个可选的基于浏览器的测试器，可在JS修改的时候刷新</p><p style="margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #333333; background-color: transparent; text-indent: 28px; ">&#9670; 其样式和语义跟Google Test for C++类似</p><p style="margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #333333; background-color: transparent; text-indent: 28px; ">&#9670; 内置的Mocking框架只需要最简单的样板代码(比如no $tearDown or $verifyAll 请求)，其样式和语义基于Google C++ Mocking Framework</p><p style="margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #333333; background-color: transparent; text-indent: 28px; ">&#9670; 匹配系统允许表达式测试，并可直观的阅读输出的错误提示，内置了很多匹配器，用户也可自行添加</p><p style="margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #333333; background-color: transparent; text-indent: 28px; ">原文：http://www.guao.hk/posts/google-js-test.html</p></div></div></span><img src ="http://www.cppblog.com/lauer3912/aggbug/157824.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-10-08 22:04 <a href="http://www.cppblog.com/lauer3912/archive/2011/10/08/157824.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>RedCrab Calculator 高数物理化工专业的科学计算器</title><link>http://www.cppblog.com/lauer3912/archive/2011/09/27/156993.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Tue, 27 Sep 2011 11:26:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/09/27/156993.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/156993.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/09/27/156993.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/156993.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/156993.html</trackback:ping><description><![CDATA[<span class="Apple-style-span" style="font-family: Verdana; background-color: #e5ecf4; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">RedCrab Calculator 是由德国人开发的科学计算器。它除了命令行功能，还带有一个图形化的全屏公式编辑器，只需用鼠标绘制几何图形、微积分、电路图等等，它就会自动计算出结果。甚至还可以显示分步求解过程，可以提高广大同学们的工作效率。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><img src="http://img.cnbeta.com/newsimg/110927/16395401626896635.png" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; "  alt="" /><img src="http://img.cnbeta.com/newsimg/110927/1639571381288583.png" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; width: 684px; height: 525px; "  alt="" /><br /><img src="http://img.cnbeta.com/newsimg/110927/1639592897139377.png" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; width: 590px; height: 500px; "  alt="" /><img src="http://img.cnbeta.com/newsimg/110927/16400131601990820.png" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; "  alt="" /><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " /></p></span><div><a href="http://www.redchillicrab.com/en/redcrab/index.html">http://www.redchillicrab.com/en/redcrab/index.html<br /><br /><span class="Apple-style-span" style="color: #000000; font-family: Simsun; line-height: normal; -webkit-text-decorations-in-effect: none; background-color: #ffffff; font-size: medium; "><table width="800" border="0" cellspacing="0" cellpadding="8"><tbody><tr><td align="center" valign="top" bgcolor="white" width="30%"><font color="white"><br /></font><table width="100%" border="0" cellspacing="2" cellpadding="0"><tbody><tr height="24"><td bgcolor="white" height="24"><div align="left"><font size="3" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"><strong>RedCrab Version 3.50.31</strong><br /><br /></font></div></td></tr><tr height="24"><td bgcolor="white" height="24"><div align="left"><font size="2" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"><a href="http://www.redchillicrab.com/en/redcrab/RedCrab_History_e.pdf" style="text-decoration: none; ">History - what's new ?<br /></a></font></div></td></tr><tr height="24"><td valign="middle" bgcolor="white" height="24"><div align="left"><font size="2" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"><a href="http://www.redchillicrab.com/en/redcrab/awards.html" style="text-decoration: none; ">Awards<br /></a></font></div></td></tr><tr height="24"><td valign="middle" bgcolor="white" height="24"><div align="left"><font size="2" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"><a href="http://www.redchillicrab.com/en/redcrab/screenshot.html" style="text-decoration: none; ">Screen Shots<br /></a></font></div></td></tr><tr height="24"><td valign="middle" bgcolor="white" height="24"><div align="left"><a href="http://www.redchillicrab.com/en/redcrab/tutor.html" style="text-decoration: none; "><font size="2" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">Tutor / Videos</font></a></div></td></tr><tr height="24"><td valign="middle" bgcolor="white" height="24"><div align="left"><font size="2" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"><a href="http://www.redchillicrab.com/en/redcrab/RedCrab_Manual_e.pdf" style="text-decoration: none; ">User Manual (pdf)<br /></a></font></div></td></tr><tr height="24"><td valign="middle" bgcolor="white" height="24"><font size="2" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"><a href="http://www.redchillicrab.com/manual/en/directory.html" style="text-decoration: none; ">.</a></font></td></tr><tr height="24"><td valign="middle" bgcolor="white" height="24"></td></tr><tr height="24"><td valign="middle" bgcolor="white" height="24"><div align="left"><font size="3" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"><a href="http://www.redchillicrab.com/download/redcrab.zip" target="_top" title="[已被迅雷破解扩展破解]
" style="text-decoration: none; ">Download RedCrab<br /></a></font></div></td></tr><tr height="24"><td valign="middle" bgcolor="white" height="24"><div align="center"></div></td></tr><tr height="24"><td valign="middle" bgcolor="white" height="24"><br /></td></tr></tbody></table><font color="white"><br /></font></td><td align="right" valign="top" bgcolor="white" width="70%"><div align="left"><font size="3" face="Times New Roman,Georgia,Times"><img src="http://www.redchillicrab.com/calculator/pics/t320.png" alt="" height="360" width="486" align="right" border="1" /><br /></font></div></td></tr><tr><td colspan="2" valign="top" bgcolor="white"><table width="100%" border="0" cellspacing="0" cellpadding="8"><tbody><tr><td colspan="2" align="left" valign="top"><hr /><font size="3" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">RedCrab - The Calculator<br /></font><br /><font size="2" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">RedCrab is a scientific calculator with a full screen formula editor. The mathematical expressions are not typed in a typical command line, but can be enter in an editor window similar to a piece of paper.&nbsp;<br /><br />The calculator's editor supports the entry of complex algebraic equations like fractions, square roots, exponents, etc. for technical and scientific applications.<br /><br />No installation of the software is required. You can just copy the software to your system and starts the program.<br /><br />Starts from external disk, for example USB flash drive or CD / DVD<br /><br /><hr /><br /></font><font size="3" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">Why RedCrab?<br /></font><font size="2" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"><br /></font><font size="2" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">No one today would want to work with word processing program that simulates a typewriter, for example, no copy, paste and edit. For typo errors, whole text must be rewritten.<br /><br />But most PC calculators are just unflexible simulations of pocket calculators.<br /><br /></font><font size="2" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">RedCrab is a calculator that exploits the possibilities of PC's. Easy to use like a pocket calculator, but provided with full screen editor, which supported corrections, saveing and printing as a word processing program.<br /><br /></font><font size="2" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">Several tasks can be written in the same worksheet. Results can be adopted in other mathematical problems as in a spreadsheet program. Images and texts can imported to describe complex calculations.<br /><br /></font></td><td align="left" valign="top" width="42%"><hr /><font size="3" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">Quick start without studying the manual<br /></font><font size="2" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"><br />The handling of the basic functions is just like a conventional calculator. There is no training required. Whoever can operate a pocket calculator can also use RedCrab without studying the manual. This guide describes fundamentally the advanced features which a normal calculator does not possess.<br /></font><br /><hr /><font size="3" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">RedCrab is portable<br /></font><p><font size="2" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">RedCrab is fully portable. The program can be started from external data storage source without installation. Settings can be stored as a file in the prorams root directory instead in the PC' s Windows registry.&nbsp;<br /></font></p><p><font size="2" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">If you start RedCrab from a USB flash drive, your settings are stored on the stick.</font><font size="2"></font></p><p><font size="2" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"></font></p><hr /><font size="2" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"></font><p>&nbsp;</p><p><font size="2" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"><strong>System requirement</strong><br /></font><font size="3" face="Times New Roman,Georgia,Times"><br /></font><font size="2" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">Minimum Pentium P4 and 500MB RAM.<br />Operating system: Microsoft *Windows&nbsp;<br /><br /><br />Operating system: Linux with Wine runtime system</font></p></td></tr><tr><td colspan="3"><hr /><br /><font size="3" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">What others think about RedCrab:<br /></font><font size="2" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"><br /><a href="http://www.itreadme.com/?p=1334http://www.itreadme.com/?p=1334" target="_blank" style="text-decoration: none; ">itreadme.com :&nbsp;</a>Red Crab&#8217;s Advantages over Windows Calculator<a href="http://www.mydigitallife.info/download-redcrab-scientific-calculator-for-complex-calculations/" target="_blank" style="text-decoration: none; "><br />mydigitallife.info</a>: Scientific Calculator For Complex Calculations<br /><a href="http://www.downloadcrew.com/article/15188-redcrab" style="text-decoration: none; ">downloadcrew.com:</a>Solve complex equations in seconds with this powerful calculator<br /></font><font size="2" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"><a href="http://tricks-collections.com/download-redcrab-free-and-portable-scientific-calculator" style="text-decoration: none; ">tricks-collections.com</a>: Free and Portable Scientific Calculator<br /></font><p>&nbsp;</p></td></tr><tr><td></td><td></td><td width="42%"></td></tr></tbody></table></td></tr></tbody></table><br /><font size="2" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">*<em>Windows</em>&nbsp;is a registered trademark of&nbsp;<em>Microsoft Corporation</em>.</font></span><br /><br /></a></div><img src ="http://www.cppblog.com/lauer3912/aggbug/156993.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-09-27 19:26 <a href="http://www.cppblog.com/lauer3912/archive/2011/09/27/156993.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Vim 秘籍表 </title><link>http://www.cppblog.com/lauer3912/archive/2011/09/25/156746.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Sun, 25 Sep 2011 02:24:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/09/25/156746.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/156746.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/09/25/156746.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/156746.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/156746.html</trackback:ping><description><![CDATA[原文：http://www.lupaworld.com/article-213530-1.html<br /><div><div><p>2011-9-20 16:43|发布者: <a href="http://home.lupaworld.com/space-uid-436905.html">红黑魂</a>|查看数: 965|评论数: 2|来自: <a href="http://linuxtoy.org/archives/vim-cheat-sheet-2.html" target="_blank">linuxtoy</a></p></div><div id="diysummarytop"></div><div><div><strong>摘要</strong>: 献给程序员们，彩色风格的 VIM 速查秘籍表，适合打印、设为桌面背景或放置到专门的数码相框。   同时还提供 300DPI 的清晰版、黑白和适用于红绿色盲人士的版本，请移步至作者站点下载。 ... ...</div></div><div id="diysummarybottom"></div><div><div id="diycontenttop"></div><table cellspacing="0" cellpadding="0"><tbody><tr><td><span style="font: normal normal normal 14px/19px tahoma, sans-serif; ">       献给程序员们，彩色风格的 VIM 速查秘籍表，适合打印、设为桌面背景或放置到专门的数码相框。</span><div><span style="font: 14px/19px tahoma, sans-serif; text-align: left; color: #000000; text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;"><p><a style="color: #bb5500; text-decoration: none;" href="http://linuxtoy.org/img/2011/09/vim_cheat_sheet_for_programmers_screen.png"></a></p><p>同时还提供 300DPI 的清晰版、黑白和适用于红绿色盲人士的版本，请移步至<a style="color: #bb5500; text-decoration: none;" href="http://michael.peopleofhonoronly.com/vim/">作者站点</a>下载。</p><p><a href="http://www.lupaworld.com/data/attachment/portal/201109/20/164303mctvdswfvcudffym.png" target="_blank"><img src="http://www.lupaworld.com/data/attachment/portal/201109/20/164303mctvdswfvcudffym.png"  alt="" /></a></p></span></div></td></tr></tbody></table></div></div><img src ="http://www.cppblog.com/lauer3912/aggbug/156746.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-09-25 10:24 <a href="http://www.cppblog.com/lauer3912/archive/2011/09/25/156746.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>分享60个来自Picons.me的全格式社交图标库</title><link>http://www.cppblog.com/lauer3912/archive/2011/09/25/156742.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Sun, 25 Sep 2011 01:37:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/09/25/156742.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/156742.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/09/25/156742.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/156742.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/156742.html</trackback:ping><description><![CDATA[原文位置：<a href="http://www.gbin1.com/tools/design/60socialiconsinallpopularformatsbypiconsme/">http://www.gbin1.com/tools/design/60socialiconsinallpopularformatsbypiconsme/<br /><span class="Apple-style-span" style="color: #bbbbbb; font-family: arial; font-size: 13px; line-height: 26px; -webkit-text-decorations-in-effect: none; background-color: #202020; "><p style="outline-width: medium; outline-style: none; outline-color: initial; ">图标设计公司Picons.me免费提供了一套60枚的图标库，这套图标支持所有的流行社交网络，并且支持多种格式：AI，EPS，PDF</p><p style="outline-width: medium; outline-style: none; outline-color: initial; ">同时有PSD和CSH格式以及不同大小的PNG格式（从16*16到512*512）。</p><p style="outline-width: medium; outline-style: none; outline-color: initial; ">最后提示，GBin1为了不让用户出现困惑，Picons.me的授权不包括这套社交图标。</p><p style="outline-width: medium; outline-style: none; outline-color: initial; "><img src="http://www.gbin1.com/backup/gbin1/generated/tools/design/60socialiconsinallpopularformatsbypiconsme/1.jpg/com.gbin1.core.ResizedThumbnail/resized1324307194.jpg" alt="" width="520" style="outline-width: medium; outline-style: none; outline-color: initial; border-top-width: 5px; border-right-width: 5px; border-bottom-width: 5px; border-left-width: 5px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-color: initial; border-top-color: #333333; border-right-color: #333333; border-bottom-color: #333333; border-left-color: #333333; " /></p><p style="outline-width: medium; outline-style: none; outline-color: initial; "><a href="http://picons.me/download-social.php" target="_blank" style="outline-width: medium; outline-style: none; outline-color: initial; color: #2b99e6; text-decoration: none; ">下载地址</a></p></span><br /></a><img src ="http://www.cppblog.com/lauer3912/aggbug/156742.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-09-25 09:37 <a href="http://www.cppblog.com/lauer3912/archive/2011/09/25/156742.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MeeGo 设备运行全部 Android 应用程序？</title><link>http://www.cppblog.com/lauer3912/archive/2011/09/25/156737.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Sun, 25 Sep 2011 01:18:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/09/25/156737.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/156737.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/09/25/156737.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/156737.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/156737.html</trackback:ping><description><![CDATA[<span class="Apple-style-span" style="font-family: Verdana, Simsun, sans-serif; font-size: 13px; line-height: normal; background-color: #ffffff; "><div class="pubDate" style="padding-bottom: 5px; margin-top: 0px; margin-right: 0px; margin-bottom: 20px; margin-left: 0px; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #dddddd; color: #666666; "><a href="http://my.oschina.net/javayou" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; color: #cc0000; outline-width: 0px; outline-style: initial; outline-color: initial; ">红薯</a>&nbsp;发布于： 2011年09月22日 (<a href="http://www.oschina.net/news/21622/openmobile-acl#comments" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; color: #3e62a6; outline-width: 0px; outline-style: initial; outline-color: initial; ">8评</a>)</div><div id="OSChina_News_21622" class="NewsContent TextContent NewsType2" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; line-height: 24px; color: #000000; font-size: 10.5pt; overflow-x: hidden; overflow-y: hidden; "><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 2em; ">啥是 OpenMobile ACL？它是一个应用程序兼容层（Application Compatibility Layer），能<strong style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">让 MeeGo 设备运行全部 Android 应用程序</strong>。</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 2em; ">据 ACL 宣称：</p><ul style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 20px; margin-right: 20px; margin-bottom: 20px; margin-left: 20px; list-style-type: disc; list-style-position: inside; "><li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">100% 兼容 Android 所有程序。</li><li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">和原生 MeeGo 程序以同样速度性能，不会拖慢速度或消耗更多电力。</li><li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">无需对 Android 程序做任何修改，不用重编译或打包。</li><li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">完整的 3D 和多媒体支持。</li><li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">支持 Android API Level 4+, NDK6 以上的程序。</li></ul><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 2em; "><a href="http://www.youtube.com/watch?v=YsRH8w6RMHQ&amp;feature=player_embedded" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; color: #3e62a6; outline-width: 0px; outline-style: initial; outline-color: initial; ">使用 MeeGo X86 1.2 进行的视频演示</a>(<a href="http://v.youku.com/v_show/id_XMzA2MzA5Njgw.html" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; color: #3e62a6; outline-width: 0px; outline-style: initial; outline-color: initial; ">朝内镜像</a>)</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 2em; "><em style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">消息来源：</em><a href="http://mge.bz/nK" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; color: #3e62a6; outline-width: 0px; outline-style: initial; outline-color: initial; ">MeeGoExperts</a></p></div></span><div><a href="http://v.youku.com/v_show/id_XMzA2MzA5Njgw.html">http://v.youku.com/v_show/id_XMzA2MzA5Njgw.html<br /><br />收藏</a>：<a href="http://u.youku.com/user_show/id_UMTk0NzM5NjU2.html">http://u.youku.com/user_show/id_UMTk0NzM5NjU2.html</a></div><img src ="http://www.cppblog.com/lauer3912/aggbug/156737.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-09-25 09:18 <a href="http://www.cppblog.com/lauer3912/archive/2011/09/25/156737.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Google C++ Testing Framework简介</title><link>http://www.cppblog.com/lauer3912/archive/2011/09/19/156261.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Mon, 19 Sep 2011 13:03:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/09/19/156261.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/156261.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/09/19/156261.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/156261.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/156261.html</trackback:ping><description><![CDATA[<span class="Apple-style-span" style="font-family: verdana, sans-serif; font-size: 12px; line-height: 18px; background-color: #f8fafd; "><p style="font-size: 14px; line-height: 25px; text-indent: 25px; "><strong>简介：</strong>&nbsp;Google 提供一种用于为 C/C++ 软件开发单元测试的开放源码框架，它很有意思，也很容易使用。本文介绍一些比较有用的 Google C++ Testing Framework 特性。本文基于 version 1.4。</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; "><strong>为什么要使用 Google C++ Testing Framework？</strong></p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">使用这个框架有许多好理由。本节讨论其中几个。</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">某些类型的测试有糟糕的内存问题，这些问题只在某几次运行期间出现。Google 的测试框架为处理这种情况提供了出色的支持。可以使用 Google 框架重复运行相同的测试一千次。当出现故障的迹象时，自动地调用调试器。另外，这只需要在命令行上传递两个开关即可实现：--gtest_repeat=1000 --gtest_break_on_failure。</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">与其他许多测试框架相反，可以把 Google 测试框架内置的断言部署在禁用了异常处理（通常由于性能原因）的软件中。因此，也可以在析构函数中安全地使用断言。</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">运行测试很简单。只需调用预定义的 RUN_ALL_TESTS 宏，而不需要通过创建或驱动单独的运行器类来执行测试。这比 CppUnit 等框架方便多了。</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">只需传递一个开关即可生成 Extensible Markup Language (XML) 报告： --gtest_output="xml:&lt;file name&gt;"。在 CppUnit 和 CppTest 等框架中，需要编写很多代码才能生成 XML 输出。</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">创建基本测试</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">请考虑 清单 1 所示的平方根函数的原型。</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; "><strong>清单 1. 平方根函数的原型</strong></p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; "></p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">double square-root (const double);</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">对于负数，这个例程返回 -1。正数测试和负数测试对它都有意义，所以我们编写两个测试。清单 2 给出测试用例。</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; "><strong>清单 2. 平方根函数的单元测试</strong></p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; "></p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">#include "gtest/gtest.h"</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">TEST (SquareRootTest, PositiveNos) {</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">EXPECT_EQ (18.0, square-root (324.0));</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">EXPECT_EQ (25.4, square-root (645.16));</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">EXPECT_EQ (50.3321, square-root (2533.310224));</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">}</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">TEST (SquareRootTest, ZeroAndNegativeNos) {</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">ASSERT_EQ (0.0, square-root (0.0));</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">ASSERT_EQ (-1, square-root (-22.0));</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">}</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">清单 2 创建一个名为 SquareRootTest 的测试层次结构，然后在其中添加两个单元测试 PositiveNos 和 ZeroAndNegativeNos。TEST 是在 gtest.h（可以在下载的源代码中找到）中定义的预定义宏，它帮助定义这个层次结构。EXPECT_EQ 和 ASSERT_EQ 也是宏 &#8212; 对于前者，即使出现测试失败，测试仍然继续执行；对于后者，测试终止执行。显然，如果 0 的平方根是除 0 之外的任何数字，就没必要再执行测试了。因此，ZeroAndNegativeNos 测试只使用 ASSERT_EQ，而 PositiveNos 测试使用 EXPECT_EQ，来报告存在多少个测试用例是平方根函数失败而不终止测试的情况。</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; "><strong>运行第一个测试</strong></p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">既然已经创建了第一个基本测试，现在就该运行它了。清单 3 是运行测试的主例程。</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; "><strong>清单 3. 运行平方根测试</strong></p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; "></p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">#include "gtest/gtest.h"</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">TEST(SquareRootTest, PositiveNos) {</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">EXPECT_EQ (18.0, square-root (324.0));</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">EXPECT_EQ (25.4, square-root (645.16));</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">EXPECT_EQ (50.3321, square-root (2533.310224));</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">}</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">TEST (SquareRootTest, ZeroAndNegativeNos) {</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">ASSERT_EQ (0.0, square-root (0.0));</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">ASSERT_EQ (-1, square-root (-22.0));</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">}</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">int main(int argc, char **argv) {</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">::testing::InitGoogleTest(&amp;argc, argv);</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">return RUN_ALL_TESTS();</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">}</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">顾名思义，::testing::InitGoogleTest 方法的作用就是对框架进行初始化，必须在调用 RUN_ALL_TESTS 之前调用它。在代码中只能调用 RUN_ALL_TESTS 一次，因为多次调用会与框架的一些高级特性冲突，不支持这种做法。注意，RUN_ALL_TESTS 自动地探测并运行用 TEST 宏定义的所有测试。在默认情况下，结果输出到标准输出。清单 4 给出输出。</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; "><strong>清单 4. 运行平方根测试的输出</strong></p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; "></p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">Running main() from user_main.cpp</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[==========] Running 2 tests from 1 test case.</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[----------] Global test environment set-up.</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[----------] 2 tests from SquareRootTest</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[ RUN ] SquareRootTest.PositiveNos</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">..\user_sqrt.cpp(6862): error: Value of: sqrt (2533.310224)</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">Actual: 50.332</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">Expected: 50.3321</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[ FAILED ] SquareRootTest.PositiveNos (9 ms)</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[ RUN ] SquareRootTest.ZeroAndNegativeNos</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[ OK ] SquareRootTest.ZeroAndNegativeNos (0 ms)</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[----------] 2 tests from SquareRootTest (0 ms total)</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[----------] Global test environment tear-down</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[==========] 2 tests from 1 test case ran. (10 ms total)</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[ PASSED ] 1 test.</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[ FAILED ] 1 test, listed below:</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[ FAILED ] SquareRootTest.PositiveNos</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">1 FAILED TEST</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; "><strong>Google C++ Testing Framework 的选项</strong></p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">在 清单 3 中，InitGoogleTest 函数接受测试基础设施的参数。本节讨论可以通过测试框架的参数实现的一些功能。</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">通过在命令行上传递 --gtest_output="xml:report.xml"，可以把输出转储为 XML 格式。当然，可以把 report.xml 替换为您喜欢的任何文件名。</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">某些测试有时候会失败，但是在大多数时候会顺利通过。这是与内存损坏相关的问题的典型特点。如果多次运行测试，就能够提高发现失败的可能性。如果在命令行上传递 --gtest_repeat=2 --gtest_break_on_failure，就重复运行相同的测试两次。如果测试失败，会自动调用调试器。</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">并不需要每次都运行所有测试，尤其是在修改的代码只影响某几个模块的情况下。为了支持运行一部分测试，Google 提供 --gtest_filter=&lt;test string&gt;。test string 的格式是由冒号 (:) 分隔的一系列通配符模式。例如，--gtest_filter=* 运行所有测试，而 --gtest_filter=SquareRoot* 只运行 SquareRootTest 测试。如果希望只运行 SquareRootTest 中的正数单元测试，应该使用 --gtest_filter=SquareRootTest.*-SquareRootTest.Zero*。注意，SquareRootTest.* 表示属于 SquareRootTest 的所有测试，而 -SquareRootTest.Zero* 表示不运行名称以 Zero 开头的测试。</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">清单 5 中的示例用 gtest_output、gtest_repeat 和 gtest_filter 选项运行 SquareRootTest。</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; "><strong>清单 5. 用 gtest_output、gtest_repeat 和 gtest_filter 选项运行 SquareRootTest</strong></p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; "></p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[arpan@tintin] ./test_executable --gtest_output="xml:report.xml" --gtest_repeat=2 --</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">gtest_filter=SquareRootTest.*-SquareRootTest.Zero*</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">Repeating all tests (iteration 1) . . .</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">Note: Google Test filter = SquareRootTest.*-SquareRootTest.Z*</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[==========] Running 1 test from 1 test case.</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[----------] Global test environment set-up.</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[----------] 1 test from SquareRootTest</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[ RUN ] SquareRootTest.PositiveNos</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">..\user_sqrt.cpp (6854): error: Value of: sqrt (2533.310224)</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">Actual: 50.332</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">Expected: 50.3321</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[ FAILED ] SquareRootTest.PositiveNos (2 ms)</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[----------] 1 test from SquareRootTest (2 ms total)</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[----------] Global test environment tear-down</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[==========] 1 test from 1 test case ran. (20 ms total)</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[ PASSED ] 0 tests.</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[ FAILED ] 1 test, listed below:</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[ FAILED ] SquareRootTest.PositiveNos</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">1 FAILED TEST</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">Repeating all tests (iteration 2) . . .</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">Note: Google Test filter = SquareRootTest.*-SquareRootTest.Z*</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[==========] Running 1 test from 1 test case.</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[----------] Global test environment set-up.</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[----------] 1 test from SquareRootTest</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[ RUN ] SquareRootTest.PositiveNos</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">..\user_sqrt.cpp (6854): error: Value of: sqrt (2533.310224)</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">Actual: 50.332</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">Expected: 50.3321</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[ FAILED ] SquareRootTest.PositiveNos (2 ms)</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[----------] 1 test from SquareRootTest (2 ms total)</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[----------] Global test environment tear-down</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[==========] 1 test from 1 test case ran. (20 ms total)</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[ PASSED ] 0 tests.</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[ FAILED ] 1 test, listed below:</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[ FAILED ] SquareRootTest.PositiveNos</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">1 FAILED TEST</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; "><strong>临时禁用测试</strong></p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">可以临时禁用测试吗？可以，只需在逻辑测试名或单元测试名前面加上 DISABLE_ 前缀，它就不会执行了。清单 6 演示如何禁用 清单 2 中的 PositiveNos 测试。</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; "><strong>清单 6. 临时禁用测试</strong></p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; "></p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">#include "gtest/gtest.h"</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">TEST (DISABLE_SquareRootTest, PositiveNos) {</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">EXPECT_EQ (18.0, square-root (324.0));</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">EXPECT_EQ (25.4, square-root (645.16));</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">EXPECT_EQ (50.3321, square-root (2533.310224));</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">}</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">OR</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">TEST (SquareRootTest, DISABLE_PositiveNos) {</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">EXPECT_EQ (18.0, square-root (324.0));</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">EXPECT_EQ (25.4, square-root (645.16));</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">EXPECT_EQ (50.3321, square-root (2533.310224));</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">}</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">注意，如果禁用了任何测试，Google 框架会在测试执行结束时输出警告消息，见 清单 7。</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; "><strong>清单 7. Google 警告用户在框架中有禁用的测试</strong></p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; "></p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">1 FAILED TEST</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">YOU HAVE 1 DISABLED TEST</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">如果希望继续运行禁用的测试，那么在命令行上传递 -gtest_also_run_disabled_tests 选项。清单 8 给出运行 DISABLE_PositiveNos 测试时的输出。</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; "><strong>清单 8. Google 允许运行已经禁用的测试</strong></p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; "></p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[----------] 1 test from DISABLED_SquareRootTest</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[ RUN ] DISABLED_SquareRootTest.PositiveNos</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">..\user_sqrt.cpp(6854): error: Value of: square-root (2533.310224)</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">Actual: 50.332</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">Expected: 50.3321</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[ FAILED ] DISABLED_SquareRootTest.PositiveNos (2 ms)</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[----------] 1 test from DISABLED_SquareRootTest (2 ms total)</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[ FAILED ] 1 tests, listed below:</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">[ FAILED ] SquareRootTest. PositiveNos</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; "><strong>断言</strong></p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">Google 测试框架提供一整套预定义的断言。断言分为两类 &#8212; 名称以 ASSERT_ 开头的断言和名称以 EXPECT_ 开头的断言。如果一个断言失败，ASSERT_* 断言会终止程序执行，而 EXPECT_* 断言继续运行。当断言失败时，这两者都输出文件名、行号和可定制的消息。比较简单的断言包括 ASSERT_TRUE (condition) 和 ASSERT_NE (val1, val2)。前者期望条件总是成立，而后者期望两个值不匹配。这些断言也适用于用户定义的类型，但是必须覆盖相应的比较操作符（==、!=、&lt;= 等等）。</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; "><strong>浮点数比较</strong></p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">Google 提供 清单 9 所示的宏以支持浮点数比较。</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; "><strong>清单 9. 用于浮点数比较的宏</strong></p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; "></p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">ASSERT_FLOAT_EQ (expected, actual)</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">ASSERT_DOUBLE_EQ (expected, actual)</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">ASSERT_NEAR (expected, actual, absolute_range)</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">EXPECT_FLOAT_EQ (expected, actual)</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">EXPECT_DOUBLE_EQ (expected, actual)</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">EXPECT_NEAR (expected, actual, absolute_range)</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">为什么需要用单独的宏进行浮点数比较？使用 ASSERT_EQ 不行吗？使用 ASSERT_EQ 和相关的宏可能可以，也可能不行，但是使用专门用于浮点数比较的宏更好。通常，不同的中央处理单元 (CPU) 和操作环境以不同的方式存储浮点数，简单地比较期望值和实际值是无效的。例如，ASSERT_FLOAT_EQ (2.00001, 2.000011) 会顺利通过 &#8212; 如果直到小数点后四位都匹配，Google 就不会抛出错误。如果需要更精确的比较，应该使用 ASSERT_NEAR (2.00001, 2.000011, 0.0000001)，就会得到 清单 10 所示的错误。</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; "><strong>清单 10. ASSERT_NEAR 产生的错误消息</strong></p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; "></p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">Math.cc(68): error: The difference between 2.00001 and 2.000011 is 1e-006, which exceeds</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">0.0000001, where</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">2.00001 evaluates to 2.00001,</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">2.000011 evaluates to 2.00001, and</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">0.0000001 evaluates to 1e-007.</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; "><strong>死亡测试</strong></p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">Google C++ Testing Framework 有一类有趣的断言（ASSERT_DEATH、ASSERT_EXIT 等），它们称为死亡断言。使用这种断言检查在例程的输入错误的情况下是否发出正确的错误消息，或者例程是否退出并返回正确的退出码。例如，在 清单 3 中，当执行 square-root (-22.0) 时应该产生错误消息，程序退出，返回状态应该是 -1 而不是 -1.0。清单 11 使用 ASSERT_EXIT 检查是否是这样。</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; "><strong>清单 11. 使用 Google 框架运行死亡测试</strong></p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; "></p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">#include "gtest/gtest.h"</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">double square-root (double num) {</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">if (num &lt; 0.0) {</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">std::cerr &lt;&lt; "Error: Negative Input\n";</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">exit(-1);</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">}</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">// Code for 0 and +ve numbers follow&#8230;</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">}</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">TEST (SquareRootTest, ZeroAndNegativeNos) {</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">ASSERT_EQ (0.0, square-root (0.0));</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">ASSERT_EXIT (square-root (-22.0), ::testing::ExitedWithCode(-1), "Error:</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">Negative Input");</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">}</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">int main(int argc, char **argv) {</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">::testing::InitGoogleTest(&amp;argc, argv);</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">return RUN_ALL_TESTS();</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">}</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">ASSERT_EXIT 检查函数是否退出并返回正确的退出码（即 exit 或 _exit 例程的参数），对引号中的字符串和函数发送到标准错误的字符串进行比较。注意，错误消息必须发送到 std::cerr 而不是 std::cout。清单 12 给出 ASSERT_DEATH 和 ASSERT_EXIT 的原型。</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; "><strong>清单 12. 死亡断言的原型</strong></p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; "></p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">ASSERT_DEATH(statement, expected_message)</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">ASSERT_EXIT(statement, predicate, expected_message)</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">Google 提供预定义的谓词 ::testing::ExitedWithCode(exit_code)。只有在程序退出且退出码与谓词中的 exit_code 相同的情况下，这个谓词的结果才是 true。ASSERT_DEATH 比 ASSERT_EXIT 简单；它只检查标准错误中的错误消息是否是用户期望的消息。</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; "><strong>理解测试装备</strong></p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">在执行单元测试之前，通常要执行一些定制的初始化。例如，如果希望度量测试的时间/内存占用量，就需要放置一些测试专用代码以度量这些值。这就是装备的用途 &#8212; 它们帮助完成这种定制的测试初始化。清单 13 给出一个装备类的示例。</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; "><strong>清单 13. 测试装备类</strong></p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; "></p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">class myTestFixture1: public ::testing::test {</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">public:</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">myTestFixture1( ) {</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">// initialization code here</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">}</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">void SetUp( ) {</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">// code here will execute just before the test ensues</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">}</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">void TearDown( ) {</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">// code here will be called just after the test completes</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">// ok to through exceptions from here if need be</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">}</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">~myTestFixture1( ) {</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">// cleanup any pending stuff, but no exceptions allowed</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">}</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">// put in any custom data members that you need</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">};</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">这个装备类派生自 gtest.h 中声明的 ::testing::test 类。清单 14 是使用这个装备类的示例。注意，它使用 TEST_F 宏而不是 TEST。</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; "><strong>清单 14. 装备的使用示例</strong></p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; "></p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">TEST_F (myTestFixture1, UnitTest1) {</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">&#8230;.</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">}</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">TEST_F (myTestFixture1, UnitTest2) {</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">&#8230;.</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">}</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">在使用装备时，要注意以下几点：</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">可以在构造函数或 SetUp 方法中执行初始化或分配资源。由用户选择具体方式。</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">可以在 TearDown 或析构函数例程中释放资源。但是，如果需要异常处理，那么只能在 TearDown 代码中进行，因为从析构函数中抛出异常会导致不确定的结果。</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">在以后的版本中，Google 断言宏可能会在平台上抛出异常。因此，为了便于维护，最好在 TearDown 代码中使用断言宏。</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">并不跨多个测试使用同一个测试装备。对于每个新的单元测试，框架创建一个新的测试装备。在 清单 14 中，由于要创建两个 myFixture1 对象，所以两次调用 SetUp 例程（请注意使用正确的拼写）。</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; "><strong>结束语</strong></p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">本文仅仅触及了 Google C++ Testing Framework 的皮毛。可以从 Google 网站获得关于这个框架的详细信息。对于高级开发人员，我建议阅读 Boost 单元测试框架和 CppUnit 等开放回归框架方面的其他文章。更多信息参见 参考资料。</p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; "><strong>关于作者</strong></p><p style="font-size: 14px; line-height: 25px; text-indent: 25px; ">Arpan Sen 是致力于电子设计自动化行业的软件开发首席工程师。他使用各种 UNIX 版本（包括 Solaris、SunOS、HP-UX、IRIX，以及 Linux 和 Microsoft Windows）已经多年。他热衷于各种软件性能优化技术、图论和并行计算。Arpan 获得了软件系统硕士学位。</p></span><img src ="http://www.cppblog.com/lauer3912/aggbug/156261.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-09-19 21:03 <a href="http://www.cppblog.com/lauer3912/archive/2011/09/19/156261.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>