<?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>Some Assembly Required &#187; The War On malloc</title>
	<atom:link href="http://assemblyrequired.crashworks.org/category/programming/the-war-on-malloc/feed/" rel="self" type="application/rss+xml" />
	<link>http://assemblyrequired.crashworks.org</link>
	<description>Technical Notes On Game Development</description>
	<lastBuildDate>Wed, 04 Nov 2009 09:52:17 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Sentences That Should Be Carved Into Foreheads</title>
		<link>http://assemblyrequired.crashworks.org/2008/12/22/ea-stl-prevents-memory-leaks/</link>
		<comments>http://assemblyrequired.crashworks.org/2008/12/22/ea-stl-prevents-memory-leaks/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 18:00:18 +0000</pubDate>
		<dc:creator>Elan</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[The War On malloc]]></category>
		<category><![CDATA[memory]]></category>

		<guid isPermaLink="false">http://assemblyrequired.crashworks.org/?p=92</guid>
		<description><![CDATA[Non-desktop platforms don't have paged memory. If the application exhausts memory, it dies.
The lack of paged memory means that memory fragmentation can kill an application. 
Therefore, game applications cannot leak memory. Ever. Period.]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html">Paul Pedriana&#8217;s article on Electronic Arts&#8217; custom</a> <a href="http://www.sgi.com/tech/stl/">STL</a> I came across this <a href="http://www.google.com/search?hl=en&amp;q=very+good+sentences+site%3Amarginalrevolution.com&amp;btnG=Search">Very Good Sentence</a> (well, okay, pair of sentences):</p>
<blockquote><p>Game applications cannot leak memory. If an application leaks even a small amount of memory, it eventually dies.</p></blockquote>
<p>I say <em>preach it</em>, brother. I can think of a couple of titles where memory leaks actually hurt a game&#8217;s sales. In fact I&#8217;ve been known to blame reckless use of <code>new</code> for the death of entire studios. <code>malloc()</code> — there&#8217;s no evil too great to lay at its feet.</p>
<p>Paul&#8217;s sentence comes in the context of a group of justifications for EA building its own Standard Template Library, which are so concisely spot-on that I&#8217;ll reproduce them here. Call them Paul&#8217;s Commandments:</p>
<p><span id="more-92"></span></p>
<blockquote>
<ul>
<li>No matter how powerful any game computer ever gets, it will never have any free memory or CPU cycles.</li>
<li>Game developers are very concerned about software performance and software development practices.</li>
<li>Game software often doesn&#8217;t use conventional synchronous disk IO such as &lt;stdio.h&gt; or &lt;fstream&gt; but uses asynchronous IO.</li>
<li>Game applications cannot leak memory. If an application leaks even a small amount of memory, it eventually dies.</li>
<li>Every byte of allocated memory must be accounted for and trackable. This is partly to assist in leak detection but is also to enforce budgeting.</li>
<li>Game software rarely uses system-provided heaps but uses custom heaps instead.</li>
<li> A lot of effort is expended in reducing memory fragmentation.</li>
<li>A lot of effort is expended in creating memory analysis tools and debugging heaps.</li>
<li>A lot of effort is expended in improving source and data build times.</li>
<li>Application code and libraries cannot be very slow in debug builds.</li>
<li>Memory allocation of any type is avoided to the extent possible.</li>
<li>Operator new overrides (class and global) are the rule and not the exception.</li>
<li>Use  of built-in global operator new is verboten, at least with shareable libraries.</li>
<li>Any memory a library allocates must be controllable by the user.</li>
<li>Game software must be savvy to non-default memory alignment requirements.</li>
<li>Memory pools are sometimes used in order to avoid fragmentation, even though they necessarily waste some memory themselves.</li>
<li>Branching (if/else/while/for/do) is avoided to the extent possible, especially mispredicted branches.</li>
<li>Virtual functions are avoided to the extent possible, especially in bottleneck code.</li>
<li>Exception handling is usually disabled. <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html#Appendix_17"><br />
</a></li>
<li>RTTI is usually disabled or at least unused in shipping code.</li>
</ul>
</blockquote>
<p>You can find <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html">the whole article here</a>; it&#8217;s a worthwhile read. If you&#8217;re in a hurry, you can safely skip the large tables; the meat of the article is in &#8220;<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html#Motivation">Motivation</a>&#8221; and the sections following &#8220;<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html#game_software_issues">Game Software Issues</a>&#8220;.</p>
]]></content:encoded>
			<wfw:commentRss>http://assemblyrequired.crashworks.org/2008/12/22/ea-stl-prevents-memory-leaks/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
