<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Cocoa Swirl</title>
	<atom:link href="http://cocoaswirl.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://cocoaswirl.com</link>
	<description>Mac and iPhone Software Development</description>
	<lastBuildDate>Tue, 21 Jul 2009 16:58:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Owning Up &#8211; Release, Retain, and Object Ownership</title>
		<link>http://cocoaswirl.com/2009/07/21/cocoa-object-ownership/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=rss</link>
		<comments>http://cocoaswirl.com/2009/07/21/cocoa-object-ownership/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 16:58:33 +0000</pubDate>
		<dc:creator>Rob Bajorek</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://cocoaswirl.com/?p=97</guid>
		<description><![CDATA[Ever used the NSString class? If you&#8217;re reading this, you probably have. Let&#8217;s look at a couple of ways to create NSStrings with the &#8230;WithFormat: methods. - (id)initWithFormat:(NSString *)format &#8230; Returns an NSString object initialized by using a given format string as a template into which the remaining argument values are substituted. + (id)stringWithFormat:(NSString *)format, [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Ever used the <a href="http://developer.apple.com/iphone/library/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html">NSString</a> class? If you&#8217;re reading this, you probably have. Let&#8217;s look at a couple of ways to create NSStrings with the <em>&#8230;WithFormat:</em> methods.</p>
<p><span style="font-family: courier new,courier;"><strong>- (id)initWithFormat:(NSString *)<em>format</em> <em>&#8230;</em></strong><br />
Returns an <em>NSString</em> object initialized by using a given format string as a template into which the remaining argument values are substituted.</span></p>
<p><span style="font-family: courier new,courier;"><strong>+ (id)stringWithFormat:(NSString *)<em>format,</em> <em>&#8230;</em></strong><br />
Returns a string created by using a given format string as a template into which the remaining argument values are substituted.</span></p>
<p>Hmm, they both sound about the same, take the same arguments, and return an NSString object.  Apple made these two functions for a reason, so what&#8217;s the difference?</p>
<p>There are semantic differences in usage, but the real difference I&#8217;m talking about is <strong>who owns the NSString object</strong>.</p>
<h3>Object Ownership in Objective-C</h3>
<p>From the object&#8217;s perspective, what does it mean to <em>be</em> owned?  According to <a href="http://devworld.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmObjectOwnership.html#//apple_ref/doc/uid/20000043-SW1">Apple&#8217;s Memory Management Guide</a>, <strong>an object exists as long as it has at least one owner</strong>.  There are no restrictions on how many owners an object has; it can have none or a hundred.  An owner relinquishes ownership by sending their object a <em>release</em> or <em>autorelease</em> message.  When the last owner has given up ownership, the application will dispose of the object automatically.</p>
<p>How do you know if an object is yours?</p>
<ul>
<li>If you create an object with <em>alloc, new, </em>or <em>copy</em>, it&#8217;s <strong>yours</strong>.</li>
<li>If you <em>retain</em> an object, it&#8217;s <strong>yours</strong>.</li>
<li>Everything else is <strong>not yours</strong>.</li>
</ul>
<p>That&#8217;s it.</p>
<p>What does that mean?  The main point of object ownership is <strong>you choose to own an object because you don&#8217;t want it deallocated</strong>.  If an object is <strong>not yours</strong> and <strong>you want to keep it around</strong>, you must <em>retain</em> it and <strong>make it yours</strong>.  Otherwise, the system may take it away from you.</p>
<p>We&#8217;re also talking about memory <em>management</em>.  <strong>You must clean up after yourself</strong>.  If an object is <strong>yours</strong> and you&#8217;re done with it, you must <em>release</em> or <em>autorelease</em> it.  If you don&#8217;t, you create a <strong>leak</strong>: allocated memory that cannot be freed because you&#8217;ve lost the reference to it.  Leaks cause memory problems, and if this is an iPhone app then Apple may reject it until you fix the mess.</p>
<h3>An example</h3>
<p>Here&#8217;s a snippet that demonstrates different ownership situations.</p>
<pre>/* Create some strings */
int count = 1;

NSString *string1 = [[NSString alloc] initWithFormat:@"This is string %d. It's mine, so I need to release it when I'm done.", count];
count++;

NSString *string2 = [NSString stringWithFormat:@"This is string %d. It is not mine, so I won't release it.", count];
count++;

NSString *string3 = [[NSString stringWithFormat:@"This is string %d. We are retaining it, so we must release it later.", count] retain];
count++;

... // code using the strings snipped

/* Done with the strings, get rid of them */
[string1 release];     // Released and gone
// [string2 release];  // string2 is not ours, so releasing it is an error
[string3 autorelease]; // Still here until NSAutoReleasePool is drained</pre>
<p>The <strong>string1</strong> object is created with <em>alloc</em> and initialized by <em>initWithFormat:</em>.  Checking the rules, <em>alloc</em> is one of our special keywords, so <strong>string1 is ours</strong>.  We need to <em>release</em> it, and in fact we do so.  No problem.</p>
<p>Our <strong>string2</strong> object is created with the <strong>NSString</strong> factory method <em>stringWithFormat:</em>.  The method name doesn&#8217;t use the ownership keywords, so <strong>string2 is not ours</strong>.  It will be <em>autoreleased</em>.  In fact, if you <em>release</em> it&#8230;</p>
<p><code>Program received signal:  “EXC_BAD_ACCESS”.</code></p>
<p>Oops!  Don&#8217;t do that!</p>
<p>Lastly, <strong>string3</strong> is an <em>autoreleased</em> string like <strong>string2</strong>, but this time we <em>retained</em> it. Using <em>retain</em> takes ownership of it, so <strong>string3 is ours</strong>.  We need to <em>release</em> it when we&#8217;re finished with it.  This time though, we chose to <em>autorelease</em> it.  We don&#8217;t own it anymore, but it&#8217;s still around.</p>
<h3>Release vs. Autorelease</h3>
<p>As we&#8217;ve seen, there are two ways to disown an object: <em>release</em> and <em>autorelease</em>.  What&#8217;s the difference?</p>
<p>If you use <em>release</em>, the effect is immediate.  If you were the last owner, that object is gone and memory is freed.</p>
<pre>CSWidget *widget = [[CSWidget alloc] init];  // New widget, owned by me
[widget shake];
[widget twirl];
[widget release];  // widget is gone</pre>
<p>Usually this is fine, but that may not be what you want.</p>
<p>Take &#8220;<strong>(NSString *)stringWithFormat: (NSString *)format, &#8230;</strong>&#8221; .  How can <strong>stringWithFormat:</strong> disown its returned object without losing it?  By using <em>autorelease</em>.</p>
<pre>+ (CSWidget *) widget {
  CSWidget *widget = [[CSWidget alloc] init];  // New widget, owned by me
  [widget autorelease];  // Not owned by me anymore, but still exists
  return widget;
}</pre>
<p>We created a widget object and disowned it, but its <em>release</em> is <strong>delayed</strong> until the current <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSAutoreleasePool_Class/Reference/Reference.html">NSAutoReleasePool</a> is <em>drained</em>.  That is a subject for another post, but simply, the pool is <em>drained</em> after every pass of the <strong>main event loop</strong>.</p>
<p>Short version: <strong>release = immediate, autorelease = delayed</strong>.</p>
<h3>For the Mac folks</h3>
<p>On Mac you can use garbage collection now, so should you put in <em>retain</em> and <em>release</em> messages if they are just no-ops? Generally no, but with one exception.  <strong>If there&#8217;s a chance you&#8217;ll port your Mac code to iPhone, I would consider using reference-count rules</strong>.  If you don&#8217;t, you&#8217;ll have to go through the code again and fix it up to work on iPhone.</p>
<h3>More information</h3>
<p>I recommend reading the <a href="http://devworld.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html">Memory Management Programming Guide for Cocoa</a> for a complete explanation of object ownership and memory management.</p>
<h3>Review</h3>
<ul>
<li>Know the ownership keywords (<em>alloc, new, copy, retain</em>)</li>
<li><em>R</em><em>etain</em> objects you want to keep</li>
<li>Don&#8217;t release objects that aren&#8217;t yours</li>
<li>Use <em>release</em> when you don&#8217;t care if an object is deallocated immediately</li>
<li>Use <em>autorelease</em> to give up ownership but delay an object&#8217;s release</li>
</ul>
<p>Good luck!</p>
<p>Copyright &copy;2010 <a href="http://cocoaswirl.com">Rob Bajorek</a>. All Rights Reserved.</p>.]]></content:encoded>
			<wfw:commentRss>http://cocoaswirl.com/2009/07/21/cocoa-object-ownership/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WWDC 2009 Videos Released</title>
		<link>http://cocoaswirl.com/2009/06/29/wwdc-2009-videos-released/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=rss</link>
		<comments>http://cocoaswirl.com/2009/06/29/wwdc-2009-videos-released/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 23:28:44 +0000</pubDate>
		<dc:creator>Rob Bajorek</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[ADC]]></category>
		<category><![CDATA[Grand Central Dispatch]]></category>
		<category><![CDATA[OpenCL]]></category>
		<category><![CDATA[WWDC]]></category>

		<guid isPermaLink="false">http://cocoaswirl.com/?p=185</guid>
		<description><![CDATA[For all of you WWDC attendees and Premier ADC members, good news!  The WWDC 2009 videos are now available! I heard rumors that this was going to take a couple of months, so I&#8217;m very happy that they are already on iTunes U. Now if you&#8217;ll excuse me, I&#8217;m going to catch the OpenCL and [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>For all of you <a href="http://developer.apple.com/wwdc/">WWDC</a> attendees and <a href="http://developer.apple.com/products/membership.html">Premier ADC</a> members, good news!  The WWDC 2009 videos are now available!</p>
<p>I heard rumors that this was going to take a couple of months, so I&#8217;m <em>very</em> happy that they are already on iTunes U.</p>
<p>Now if you&#8217;ll excuse me, I&#8217;m going to catch the <a href="http://www.apple.com/macosx/technology/#opencl">OpenCL</a> and<a href="http://www.apple.com/macosx/technology/#grandcentral"> Grand Central Dispatch</a> sessions I missed the first time!</p>
<p>Click <a href="http://developer.apple.com/adconitunes">here</a> for ADC on iTunes and the videos.  (WWDC 2009 attendees and Premier ADC members only.)</p>
<p>Copyright &copy;2010 <a href="http://cocoaswirl.com">Rob Bajorek</a>. All Rights Reserved.</p>.]]></content:encoded>
			<wfw:commentRss>http://cocoaswirl.com/2009/06/29/wwdc-2009-videos-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Five Points From Attending WWDC 2009</title>
		<link>http://cocoaswirl.com/2009/06/18/five-points-from-attending-wwdc-2009/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=rss</link>
		<comments>http://cocoaswirl.com/2009/06/18/five-points-from-attending-wwdc-2009/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 23:02:07 +0000</pubDate>
		<dc:creator>Rob Bajorek</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Business]]></category>
		<category><![CDATA[San Francisco]]></category>
		<category><![CDATA[WWDC]]></category>

		<guid isPermaLink="false">http://cocoaswirl.com/?p=150</guid>
		<description><![CDATA[I&#8217;m back home from Apple&#8217;s Worldwide Developers Conference in San Francisco.  It was my first time, and a fun, productive experience.  There are some great posts about WWDC that I read before I went, but here are some more things I noticed: #1 — If you don&#8217;t live for the keynote, just fly in Monday [...]]]></description>
			<content:encoded><![CDATA[<p></p><p><a href="http://cocoaswirl.com/wordpress/wp-content/uploads/2009/06/wwdc2009_frontdoor.jpg"><img class="aligncenter size-medium wp-image-168" title="Front entrance of Moscone West at WWDC 2009" src="http://cocoaswirl.com/wordpress/wp-content/uploads/2009/06/wwdc2009_frontdoor-300x225.jpg" alt="Front entrance of Moscone West at WWDC 2009" width="300" height="225" /></a></p>
<p>I&#8217;m back home from Apple&#8217;s <a href="http://developer.apple.com/wwdc/">Worldwide Developers Conference</a> in San Francisco.  It was my first time, and a fun, productive experience.  There are some <a href="http://iphonedevelopment.blogspot.com/2009/03/wwdc-first-time-guide.html">great</a> <a href="http://inessential.com/2009/06/06/brent%E2%80%99s-wwdc-tips">posts</a> about WWDC that I read before I went, but here are some more things I noticed:</p>
<h3>#1 — If you don&#8217;t live for the keynote, just fly in Monday morning</h3>
<p>I heard stories about crazy lines for the keynote, so my friend and I decided to just show up around 9:30.  When we arrived, they weren&#8217;t letting people in yet and the line wrapped around the whole convention center.  Forget that!  We went to a coffee shop, followed a live Twitter feed, and went back around 10:20.  Much better, walked into the overflow room and saw almost all of the show.  Next year I’m coming to SF on Monday morning and joining the overflow crowd again.</p>
<h3>#2 — It&#8217;s easy to make friends&#8230;</h3>
<p>&#8230; but most people there aren&#8217;t going to strike up a conversation.  It&#8217;s up to you to make the first move.   It&#8217;s ok!  Mac geeks are friendly and you can <a href="http://www.appmobi.com/">meet</a> some <a href="http://iphone.pankaku.com/">interesting people</a>.  (However, I didn&#8217;t have anyone come up to <em>me</em> who wasn&#8217;t trying to sell me something, so please don&#8217;t be <em>that</em> person.)</p>
<h3>#3 — Don&#8217;t pass out business cards to random people</h3>
<p>This concept is Business 101 in my opinion, but  I don&#8217;t offer my business card to someone unless we&#8217;ve established a relationship.  Handing out cards to people walking by is just wasting money and generating ill will.   A few guys were doing this inside <a href="http://www.moscone.com/">Moscone West</a>; their cards went right in the trash.</p>
<h3>#4 — Know where to find power outlets</h3>
<p><a href="http://cocoaswirl.com/wordpress/wp-content/uploads/2009/06/wwdc2009_powerstrip.png"><img class="size-full wp-image-162 alignright" title="Power strip from seating at WWDC 2009" src="http://cocoaswirl.com/wordpress/wp-content/uploads/2009/06/wwdc2009_powerstrip.png" alt="Power strip from seating at WWDC 2009" width="200" height="237" /></a><br />
If you&#8217;re at WWDC, you probably have a laptop.  I was worried about keeping charged throughout the day, but it wasn&#8217;t a problem at all!</p>
<p>The session rooms had power strips like the one pictured mixed in with the seats. They weren&#8217;t always in every row, so sometimes you would plug into the row behind.  When you&#8217;re roaming Moscone West, there were a number of tables with power strips, as well.  Also, in the hallways there were small clusters of power outlets in the walls that many people overlooked.</p>
<h3>#5 — Almost every seat is a good one</h3>
<p>The display screens were very large and the acoustics good in every room. Unless you want to see the speakers up close, you can sit pretty much anywhere.</p>
<p>For the heck of it, I did sit in the front row for one session.  I ended up with a sore neck from trying to see the screen.  Just sit in the middle.</p>
<h3>Anything else?</h3>
<p>Feel free to post your own comments and accumulated wisdom from WWDC!</p>
<p>Copyright &copy;2010 <a href="http://cocoaswirl.com">Rob Bajorek</a>. All Rights Reserved.</p>.]]></content:encoded>
			<wfw:commentRss>http://cocoaswirl.com/2009/06/18/five-points-from-attending-wwdc-2009/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Example project for the Cheetah3D header converter</title>
		<link>http://cocoaswirl.com/2009/06/08/example-project-for-the-cheetah3d-header-converter/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=rss</link>
		<comments>http://cocoaswirl.com/2009/06/08/example-project-for-the-cheetah3d-header-converter/#comments</comments>
		<pubDate>Tue, 09 Jun 2009 01:08:51 +0000</pubDate>
		<dc:creator>Rob Bajorek</dc:creator>
				<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Cheetah3D]]></category>
		<category><![CDATA[OpenGL ES]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://cocoaswirl.com/?p=145</guid>
		<description><![CDATA[Some folks have asked me for examples of how my Cheetah3D -&#62; iPhone header converter works. To help you out, I&#8217;m posting an Xcode project that I&#8217;m using to test the converter. You can get it here: C3DConverterTest.tgz This project renders four different shapes generated in Cheetah3D. It&#8217;s pretty simple; a lot of the code [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Some folks have asked me for examples of how my <a href="http://cocoaswirl.com/2009/05/09/cheetah3d-header-file-converter-for-iphone/">Cheetah3D -&gt; iPhone header converter</a> works.  To help you out, I&#8217;m posting an Xcode project that I&#8217;m using to test the converter.</p>
<p>You can get it here: <a href="http://cocoaswirl.com/files/C3DConverterTest.tgz">C3DConverterTest.tgz</a></p>
<p>This project renders four different shapes generated in <a href="http://cheetah3d.com">Cheetah3D</a>.  It&#8217;s pretty simple; a lot of the code is from the Xcode&#8217;s standard <a href="http://www.khronos.org/opengles/">OpenGL ES</a> project template.  I&#8217;ve added <a href="http://www.glprogramming.com/red/chapter05.html">lighting</a> to show that the normals work properly, though.</p>
<p>Some notable files:</p>
<ul>
<li> <strong>4 shapes.jas</strong> — the Cheetah3D project</li>
<li> <strong>4 shapes.h</strong> — the header file exported from Cheetah3D.  You can run this through the converter yourself if you like.</li>
<li> <strong>4 shapes_iphone.h</strong> — the header file made by my converter</li>
<li> <strong>pure_colors.jpg</strong> — A simple texture.  Replace this with your own for a different look.</li>
</ul>
<p>I hope this helps!  Let me know if you have questions or comments.</p>
<p>Copyright &copy;2010 <a href="http://cocoaswirl.com">Rob Bajorek</a>. All Rights Reserved.</p>.]]></content:encoded>
			<wfw:commentRss>http://cocoaswirl.com/2009/06/08/example-project-for-the-cheetah3d-header-converter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Version 2.0.1 of Cheetah3D header file converter for iPhone released</title>
		<link>http://cocoaswirl.com/2009/06/04/version-201-of-cheetah3d-header-file-converter-for-iphone-released/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=rss</link>
		<comments>http://cocoaswirl.com/2009/06/04/version-201-of-cheetah3d-header-file-converter-for-iphone-released/#comments</comments>
		<pubDate>Fri, 05 Jun 2009 01:56:49 +0000</pubDate>
		<dc:creator>Rob Bajorek</dc:creator>
				<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Cheetah3D]]></category>
		<category><![CDATA[OpenGL ES]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://cocoaswirl.com/?p=138</guid>
		<description><![CDATA[I&#8217;ve updated the Cheetah3D -&#62; iPhone header file converter to version 2.0.1.  This version corrects object names from Cheetah3D that aren&#8217;t valid in Objective-C.  (Example: &#8220;Box.1&#8243; is renamed to &#8220;Box_1&#8243;).  Thanks to reader Scott for pointing out the problem and a solution. Download version 2.0.1 here: c3d_to_iphone.pl (zipped) Please comment or contact me with any [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>I&#8217;ve updated the <a href="http://cheetah3d.com">Cheetah3D</a> -&gt; iPhone header file converter to <strong>version 2.0.1</strong>.  This version corrects object names from Cheetah3D that aren&#8217;t valid in Objective-C.  (Example: &#8220;Box.1&#8243; is renamed to &#8220;Box_1&#8243;).  Thanks to reader Scott for pointing out <a href="http://cocoaswirl.com/2009/05/09/cheetah3d-header-file-converter-for-iphone/comment-page-1/#comment-20">the problem and a solution</a>.</p>
<p>Download <strong>version 2.0.1</strong> here: <a href="http://cocoaswirl.com/files/c3d_to_iphone_h_pl.zip">c3d_to_iphone.pl</a> (zipped)</p>
<p>Please comment or <a href="http://cocoaswirl.com/contact/">contact</a> me with any feedback!</p>
<p>Copyright &copy;2010 <a href="http://cocoaswirl.com">Rob Bajorek</a>. All Rights Reserved.</p>.]]></content:encoded>
			<wfw:commentRss>http://cocoaswirl.com/2009/06/04/version-201-of-cheetah3d-header-file-converter-for-iphone-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone OpenGL Speed Tip &#8211; Turn Off Thumb Instructions</title>
		<link>http://cocoaswirl.com/2009/05/20/iphone-opengl-speed-tip-turn-off-thumb-instructions/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=rss</link>
		<comments>http://cocoaswirl.com/2009/05/20/iphone-opengl-speed-tip-turn-off-thumb-instructions/#comments</comments>
		<pubDate>Thu, 21 May 2009 00:09:47 +0000</pubDate>
		<dc:creator>Rob Bajorek</dc:creator>
				<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[ARM]]></category>
		<category><![CDATA[multithreading]]></category>
		<category><![CDATA[OpenGL ES]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[Thumb]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://cocoaswirl.com/?p=95</guid>
		<description><![CDATA[Want to boost your iPhone OpenGL app&#8217;s framerate with one checkbox?  It&#8217;s easy; turn off Thumb instructions. What are Thumb instructions? The iPhone uses the ARM 1176JZ processor, and Thumb instructions are 16-bit versions of common 32-bit ARM instructions.  By default, your Xcode project will compile with Thumb instructions. Why use Thumb instructions? On embedded [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Want to boost your iPhone OpenGL app&#8217;s framerate with one checkbox?  It&#8217;s easy; <strong>turn off Thumb instructions</strong>.</p>
<h3>What are Thumb instructions?</h3>
<p>The iPhone uses the <a href="http://www.arm.com">ARM</a> <a href="http://www.arm.com/products/CPUs/ARM1176.html">1176JZ processor</a>, and <a href="http://www.arm.com/products/CPUs/archi-thumb.html">Thumb</a> instructions are <a href="http://infocenter.arm.com/help/topic/com.arm.doc.ddi0301g/ch01s04s02.html">16-bit versions of common 32-bit ARM instructions</a>.  By default, your Xcode project will compile with <a href="http://infocenter.arm.com/help/topic/com.arm.doc.ddi0301g/Cacbdgdh.html">Thumb instructions</a>.</p>
<h3>Why use Thumb instructions?</h3>
<p>On <a href="http://en.wikipedia.org/wiki/Embedded_system">embedded systems</a> like the iPhone (or any system, really, but here especially), you have to think about the space your app uses.  Smaller instructions mean smaller code in memory and on disk.  That&#8217;s a good thing!  However, there&#8217;s a trade-off: <em>performance</em>.</p>
<p>According to <a href="http://developer.apple.com/iPhone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/ApplicationEnvironment/ApplicationEnvironment.html#//apple_ref/doc/uid/TP40007072-CH7-SW62">Apple</a>, the cost comes from floating-point operations.   Ripping out the GLfloats from your app isn&#8217;t the way to go, so let&#8217;s learn a better way.</p>
<h3>How do I turn off Thumb instructions?</h3>
<p>Here&#8217;s what to do in Xcode:</p>
<ol>
<li>Open your project</li>
<li>Choose <strong>Project -&gt; Edit Project Settings</strong></li>
<li>In the <strong>Project Info</strong> window, choose the <strong>Build </strong>tab</li>
<li>In the search box, type &#8220;<strong>thumb</strong>&#8220;</li>
<li>You should see a &#8220;<strong>Compile for Thumb</strong>&#8221; setting.  Uncheck it. (Click image to enlarge.)<br />
<a href="http://cocoaswirl.com/wordpress/wp-content/uploads/2009/05/compile_for_thumb_option.png"><img class="alignnone size-medium wp-image-110" title="Where to find the Compile for Thumb option" src="http://cocoaswirl.com/wordpress/wp-content/uploads/2009/05/compile_for_thumb_option-300x294.png" alt="Window showing the Compile for Thumb option" width="300" height="294" /></a></li>
<li>Clean and rebuild your project.</li>
</ol>
<p>That&#8217;s it!  If you don&#8217;t have the setting, make sure the Active SDK is set to <strong>Device</strong>.  The setting isn&#8217;t applicable to the <strong>Simulator</strong>.</p>
<h3>What kind of frame rate boost will I see?</h3>
<p>I had improvements of around 20, 30, and 50%.  Hopefully you will see even bigger ones!</p>
<p>Copyright &copy;2010 <a href="http://cocoaswirl.com">Rob Bajorek</a>. All Rights Reserved.</p>.]]></content:encoded>
			<wfw:commentRss>http://cocoaswirl.com/2009/05/20/iphone-opengl-speed-tip-turn-off-thumb-instructions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cheetah3D header file converter for iPhone</title>
		<link>http://cocoaswirl.com/2009/05/09/cheetah3d-header-file-converter-for-iphone/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=rss</link>
		<comments>http://cocoaswirl.com/2009/05/09/cheetah3d-header-file-converter-for-iphone/#comments</comments>
		<pubDate>Sun, 10 May 2009 04:11:23 +0000</pubDate>
		<dc:creator>Rob Bajorek</dc:creator>
				<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Cheetah3D]]></category>
		<category><![CDATA[OpenGL ES]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://cocoaswirl.com/?p=41</guid>
		<description><![CDATA[[Update 2009/06/04: Version 2.0.1 released.  Bug fix release, see here for more information.] It&#8217;s ready!  The promised Cheetah3D -&#62; iPhone header converter is right here: c3d_to_iphone_h.pl (zipped) With this program you can convert exported Cheetah3D OpenGL .h files to an iPhone-compatible format. Please read the comments at the top of the program file for usage [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>[Update 2009/06/04: Version 2.0.1 released.  Bug fix release, see <a href="http://cocoaswirl.com/2009/06/04/version-201-of-cheetah3d-header-file-converter-for-iphone-released/">here</a> for more information.]</p>
<p>It&#8217;s ready!  The <a href="/2009/05/07/finding-a-3d-modelling-application-for-iphone-development/" target="_self">promised</a> Cheetah3D -&gt; iPhone header converter is right here:</p>
<h4><a href="/files/c3d_to_iphone_h_pl.zip">c3d_to_iphone_h.pl</a> (zipped)</h4>
<p>With this program you can convert exported <a href="http://cheetah3d.com">Cheetah3D</a> OpenGL .h files to an iPhone-compatible format.</p>
<p>Please read the comments at the top of the program file for usage information.  I tested this on Mac OS X 10.5.6, but it should work on any system with <a href="http://dev.perl.org/perl5/">Perl 5</a>.  I purposely did not use any <a href="http://cpan.org/modules/index.html">external modules</a> (no messing with <a href="http://cpan.org/">CPAN</a> here.)</p>
<p>The software is free, licensed under <a href="http://www.gnu.org/licenses/gpl.html">GPL 3</a>.  If you try it, please <a href="/contact">send feedback</a> or respond in the comments.  Thanks!</p>
<p>Copyright &copy;2010 <a href="http://cocoaswirl.com">Rob Bajorek</a>. All Rights Reserved.</p>.]]></content:encoded>
			<wfw:commentRss>http://cocoaswirl.com/2009/05/09/cheetah3d-header-file-converter-for-iphone/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>You Have to Learn the Magic</title>
		<link>http://cocoaswirl.com/2009/05/08/you-have-to-learn-the-magic/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=rss</link>
		<comments>http://cocoaswirl.com/2009/05/08/you-have-to-learn-the-magic/#comments</comments>
		<pubDate>Sat, 09 May 2009 04:09:52 +0000</pubDate>
		<dc:creator>Rob Bajorek</dc:creator>
				<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Magical thinking]]></category>
		<category><![CDATA[Memory management]]></category>

		<guid isPermaLink="false">http://cocoaswirl.com/?p=44</guid>
		<description><![CDATA[Bad things can happen when you don&#8217;t understand what you&#8217;re doing. When writing my first iPhone application in Objective-C, I banged my head against the wall of memory management. EXC_BAD_ACCESS became a frequent and unwelcome guest during testing. I have a C/C++ background, so picking up Objective-C was not particularly difficult. However, Objective-C objects are [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Bad things can happen when you don&#8217;t understand what you&#8217;re doing.</p>
<p>When writing my first iPhone application in Objective-C, I banged my head against the wall of <a href="http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html">memory management</a>.  <strong>EXC_BAD_ACCESS became a frequent and unwelcome guest during testing</strong>.</p>
<p>I have a C/C++ background, so picking up Objective-C was not particularly difficult.  However, <a href="http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocObjectsClasses.html#//apple_ref/doc/uid/TP30001163-CH11-SW2" target="_self">Objective-C objects</a> are a different beast than I was used to.  I soon noticed a theme while debugging my app; crashes happened around the words <em>release</em> and <em>dealloc</em> a lot.</p>
<p>I started sprinkling <em>retains</em> throughout my code, hoping to ward off the memory errors.  Sometimes it worked, sometimes I created a <a href="http://developer.apple.com/documentation/DeveloperTools/Conceptual/InstrumentsUserGuide/Built-InInstruments/Built-InInstruments.html#//apple_ref/doc/uid/TP40004652-CH6-SW26" target="_self">leak</a>, and sometimes the crash jumped somewhere else.  <strong>It was like playing <a href="http://en.wikipedia.org/wiki/Whack-a-mole" target="_self">whack-a-mole</a>.</strong> Bash a bug in one place, and it popped up in another.</p>
<p>The problem was, <strong>to me, Objective-C memory management was something magical.</strong> I created and deleted objects all the time, and usually it worked.  But, I didn&#8217;t know the rules for when to <em>retain</em>. I was trusting the object fairies to know what I wanted to keep and what to whisk away.</p>
<p>Eventually, I stopped and said &#8220;There is something fundamental that I&#8217;m missing.&#8221;  I spent an hour reading Apple&#8217;s <a href="http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html">Memory Management Programming Guide for Cocoa</a>.  It was like flipping on a switch in my head.  I went back to my code, ripped out the useless <em>retains</em>, then picked off the bugs one by one.</p>
<p><strong>Magical thinking is a recipe for disaster.</strong> You need to understand the tools you use.  If something is a <a href="http://en.wikipedia.org/wiki/Black_box" target="_self">black box</a> to you, take a <a href="http://www.willitblend.com/videos.aspx?type=unsafe&amp;video=crowbar" target="_self">crowbar</a> and rip it open.</p>
<p>Don&#8217;t trust the fairies.  They don&#8217;t take the support calls from your frustrated customers.  Learn the magic yourself.</p>
<p>Copyright &copy;2010 <a href="http://cocoaswirl.com">Rob Bajorek</a>. All Rights Reserved.</p>.]]></content:encoded>
			<wfw:commentRss>http://cocoaswirl.com/2009/05/08/you-have-to-learn-the-magic/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Finding a 3D Modelling Application for iPhone Development</title>
		<link>http://cocoaswirl.com/2009/05/07/finding-a-3d-modelling-application-for-iphone-development/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=rss</link>
		<comments>http://cocoaswirl.com/2009/05/07/finding-a-3d-modelling-application-for-iphone-development/#comments</comments>
		<pubDate>Thu, 07 May 2009 05:10:30 +0000</pubDate>
		<dc:creator>Rob Bajorek</dc:creator>
				<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Blender]]></category>
		<category><![CDATA[Cheetah3D]]></category>
		<category><![CDATA[OpenGL ES]]></category>

		<guid isPermaLink="false">http://cocoaswirl.com/?p=36</guid>
		<description><![CDATA[After starting down the road of OpenGL development on the iPhone, I knew I needed a 3D modeling application to do anything fancier than spheres and cubes. My first try at an application was Blender. Blender has a lot of fans, but it’s also quite complicated. Just going through the tutorials was a chore. I [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>After starting down the road of <a href="http://cocoaswirl.com/2009/05/06/my-start-with-opengl-es-for-iphone/" target="_self">OpenGL development on the iPhone</a>, I knew I needed a 3D modeling application to do anything fancier than <a rel="self" href="http://pyopengl.sourceforge.net/documentation/manual/glutSolidSphere.3GLUT.xml">spheres</a> and <a rel="self" href="http://pyopengl.sourceforge.net/documentation/manual/glutSolidCube.3GLUT.xml">cubes</a>.  My first try at an application was <a rel="self" href="http://www.blender.org/">Blender</a>.  <strong>Blender has a lot of fans, but it’s also quite complicated</strong>.  Just going through the <a rel="self" href="http://en.wikibooks.org/wiki/Blender_3D:_Noob_to_Pro">tutorials</a> was a chore.  I didn’t want to learn how to draw fancy shapes like <a rel="self" href="http://www.harkyman.com/bmau.html">monkeys</a>; simple polygons were sufficient.</p>
<p>After getting some basic models together in Blender, I had difficulty exporting into a usable format for the iPhone.  The <a rel="self" href="http://local.wasp.uwa.edu.au/%7Epbourke/dataformats/obj/">Wavefront OBJ format</a> is the generic 3D model standard, and there is an <a rel="self" href="http://code.google.com/p/iphonewavefrontloader/">importer for iPhone</a> out there.  It’s not feature complete, and doesn’t support <a rel="self" href="http://en.wikipedia.org/wiki/UV_mapping">UV texture mapping</a> at this time.  That’s a big hole for my purposes.</p>
<p>I played with Blender for a couple of days, but I struggled getting textured Blender objects into my iPhone project. Other people do it, so I’m sure it’s my lack of knowledge in that field. <strong>However, I don’t plan on being a 3d modeler; I’m the software architect.</strong> I need to spend my time on my area of expertise. But my needs were simple (mostly basic textured polygons), so I still preferred to do it myself.</p>
<p>What did I do?  <strong>I ended up buying </strong><strong><a rel="self" href="http://cheetah3d.com/">Cheetah3D</a></strong>, made my shapes quickly (and easily!), and exported it to a .h file in<strong> under 15 minutes</strong>.  Now that’s what was looking for from Blender!</p>
<p>All done?  Close, but not quite.  <a rel="self" href="http://cheetah3d.com/about_5.php">Cheetah3D’s .h export feature</a> makes an OpenGL-compatible file, not an OpenGL ES one. But, it took under an hour to hammer out a Perl program to convert the header file into an iPhone-usable one. Now I just run my Perl program over Cheetah’s exports and *poof*! Add the new header file to my iPhone project, import it at the appropriate place, and it Just Works.</p>
<p>End result?  <strong>Cheetah3D is doing everything I need in a 3D tool.</strong> Not to say that Blender is a bad program. Far from it; it has an enormous amount of power and it’s free. But just like you won’t recommend <a rel="self" href="http://www.adobe.com/products/photoshop/family/">Photoshop</a> to get rid of <a rel="self" href="http://www.colorpilot.com/redeye_effect.html">red-eye</a>, for my basic needs Cheetah3D does the job.</p>
<p>I have some requests for my Perl program, so as soon as I clean it up I&#8217;ll put it out for you to use.</p>
<p>[Update 2009/05/09] The Cheetah3D -&gt; iPhone header converter has been <a href="http://cocoaswirl.com/2009/05/09/cheetah3d-header-file-converter-for-iphone/">posted</a>.</p>
<p>Copyright &copy;2010 <a href="http://cocoaswirl.com">Rob Bajorek</a>. All Rights Reserved.</p>.]]></content:encoded>
			<wfw:commentRss>http://cocoaswirl.com/2009/05/07/finding-a-3d-modelling-application-for-iphone-development/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>My Start with OpenGL ES for iPhone</title>
		<link>http://cocoaswirl.com/2009/05/06/my-start-with-opengl-es-for-iphone/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=rss</link>
		<comments>http://cocoaswirl.com/2009/05/06/my-start-with-opengl-es-for-iphone/#comments</comments>
		<pubDate>Thu, 07 May 2009 04:57:01 +0000</pubDate>
		<dc:creator>Rob Bajorek</dc:creator>
				<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Bullet Physics]]></category>
		<category><![CDATA[OpenGL ES]]></category>

		<guid isPermaLink="false">http://cocoaswirl.com/?p=27</guid>
		<description><![CDATA[This post is about my start at OpenGL programming on the iPhone. I have an iPhone project that needs animation.  After considering using 2D vs. 3D objects, OpenGL looked like the best option.  Once I made that decision, I needed to start learning OpenGL. And how did that go? Let’s just say learning OpenGL is [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>This post is about my start at <a rel="self" href="http://www.opengl.org/">OpenGL</a> programming on the iPhone.</p>
<p>I have an iPhone project that needs animation.  After considering using 2D vs. 3D objects, OpenGL looked like the best option.  Once I made that decision, I needed to start learning OpenGL.  And how did that go?  Let’s just say <strong>learning OpenGL is a non-trivial exercise</strong>.</p>
<h3>First stop, the Apple Docs</h3>
<p>The natural place to start learning OpenGl for iPhone is Apple.  The <a rel="self" href="http://developer.apple.com/iphone/">iPhone Developer site</a> has a lot of information about iPhone programming.  In particular, the <a rel="self" href="http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/Introduction/Introduction.html">iPhone Application Programming Guide</a> has a <a rel="self" href="http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/GraphicsandDrawing/GraphicsandDrawing.html#//apple_ref/doc/uid/TP40007072-CH10-SW27">section</a> on OpenGL ES. The information starts with setting up a drawing context and view for OpenGL. There are a number of suggestions, lists of supported features, and comparisons between the simulator and the device. But, it doesn’t really talk about programming in OpenGL. In short,<strong> it’s a great list of tips, but it assumes you already know what you’re doing.</strong> Surely I’ll come back to this page, but it’s not the place to start.</p>
<p>Apple did include some links, though.  That’s where I went next.</p>
<h3>OpenGL ES, the standard</h3>
<p>I said before that iPhone OpenGL is not the full spec.  It’s a special system designed for embedded devices and <a rel="self" href="http://www.us.playstation.com/PS3/landing.aspx">consoles</a> called <a rel="self" href="http://www.khronos.org/opengles/">OpenGL ES</a>, specifically <a rel="self" href="http://www.khronos.org/opengles/1_X/">version 1.1</a>.  The keepers of the standard are the <a rel="self" href="http://www.khronos.org/">Khronos Group</a>.</p>
<p>The main document that I used from Khronos was the <a rel="self" href="http://www.khronos.org/registry/gles/specs/1.1/es_full_spec.1.1.12.pdf">OpenGL ES 1.1.12 Full Specification (PDF)</a>.  <strong>This document describes the specification, although the target audience is the OpenGL ES implementor, not the application programmer.</strong> Still, I picked up core concepts like matrix modes and building polygons.  I couldn’t actually <em>do</em> anything with that knowledge since it didn’t tell me how to build an app.</p>
<p>At this point, I decided to <a rel="self" href="http://www.google.com/search?q=beginning+opengl+programming">ask Google</a>.</p>
<h3>The Red Book</h3>
<p>I looked through some forums and tutorials, and the suggestion I tried next was to learn from the “official” guide to OpenGL, AKA <a rel="self" href="http://www.glprogramming.com/red/index.html">the Red Book</a>.  By far, <strong>the official guide was the best introduction I found to OpenGL.</strong> This guide is an actual introduction, teaching you how to program from scratch.</p>
<p>This reminds me of an important point; <strong>OpenGL is a C API, not an Objective-C one.</strong> No classes or methods here. It’s globals and functions. There’s not much difference, but it may confuse you a bit if you started with Objective-C.</p>
<p>After digging into this book, I started to understand how OpenGL works and I could actually write code! It didn’t translate one-to-one to the iPhone because this is an OpenGL book, not an OpenGL ES one. However, it wasn’t difficult to apply the book to the iPhone. If I did get stuck, someone else did too and I found an answer from Google.</p>
<p>Also, <a rel="self" href="http://developer.apple.com/iphone/library/navigation/Frameworks/Media/OpenGLES/index.html">Apple’s OpenGL ES examples</a> made more sense.  I started with those and built on them while going through the Red Book.</p>
<h3>The Recommendation</h3>
<p>I feel comfortable with OpenGL ES now.  In fact, I already have a working 3D app integrated with the <a rel="self" href="http://www.bulletphysics.com/">Bullet Physics library</a> (a topic for another day.)  My recommendation if you’re starting from scratch is to <strong>use the Red Book and the OpenGL examples from Apple.</strong> Play with the example projects until you feel comfortable, then go from there.</p>
<p>Copyright &copy;2010 <a href="http://cocoaswirl.com">Rob Bajorek</a>. All Rights Reserved.</p>.]]></content:encoded>
			<wfw:commentRss>http://cocoaswirl.com/2009/05/06/my-start-with-opengl-es-for-iphone/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Welcome to Cocoa Swirl!</title>
		<link>http://cocoaswirl.com/2009/05/06/welcome-to-cocoa-swirl/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=rss</link>
		<comments>http://cocoaswirl.com/2009/05/06/welcome-to-cocoa-swirl/#comments</comments>
		<pubDate>Thu, 07 May 2009 04:20:56 +0000</pubDate>
		<dc:creator>Rob Bajorek</dc:creator>
				<category><![CDATA[Meta]]></category>

		<guid isPermaLink="false">http://cocoaswirl.com/?p=20</guid>
		<description><![CDATA[Hello, and welcome! This blog is the new home for my thoughts on developing software for Mac and iPhone.  My old blog was at the website of my company, SakariTech.  The system I used there wasn&#8217;t flexible enough, so I&#8217;ve moved it to this new domain and backend. Please go to my contact page if [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Hello, and welcome!</p>
<p>This blog is the new home for my thoughts on developing software for Mac and iPhone.  My old blog was at the website of my company, <a href="http://sakaritech.com" target="_self">SakariTech</a>.  The system I used there wasn&#8217;t flexible enough, so I&#8217;ve moved it to this new domain and backend.</p>
<p>Please go to my <a href="http://cocoaswirl.com/contact/" target="_self">contact page</a> if you&#8217;d like to get ahold of me. Suggestions and comments are welcome.</p>
<p>Thanks for visiting!</p>
<p>Copyright &copy;2010 <a href="http://cocoaswirl.com">Rob Bajorek</a>. All Rights Reserved.</p>.]]></content:encoded>
			<wfw:commentRss>http://cocoaswirl.com/2009/05/06/welcome-to-cocoa-swirl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
