<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Function Memoization</title><link>http://blogs.msdn.com/wesdyer/archive/2007/01/26/function-memoization.aspx</link><description>One of my favorite pastimes is playing games. No not XBox 360, PS3, or Wii games nor other computer games, but board games, card games, and other such games. It's probably because I'm from a large family - I have 8 siblings - and we would often spend</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Function Memoization</title><link>http://blogs.msdn.com/wesdyer/archive/2007/01/26/function-memoization.aspx#1537310</link><pubDate>Fri, 26 Jan 2007 19:41:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1537310</guid><dc:creator>Heath Stewart</dc:creator><description>&lt;p&gt;Wow, someone else that has heard of Robo Rally. That is a fun game. Have fun with your project.&lt;/p&gt;
</description></item><item><title>re: Function Memoization</title><link>http://blogs.msdn.com/wesdyer/archive/2007/01/26/function-memoization.aspx#1545209</link><pubDate>Sun, 28 Jan 2007 06:38:55 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1545209</guid><dc:creator>damien morton</dc:creator><description>&lt;p&gt;Theres a great article on using memoisation to speed up Conways Game Of Life here: &lt;a rel="nofollow" target="_new" href="http://www.ddj.com/dept/ai/184406478"&gt;http://www.ddj.com/dept/ai/184406478&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The basic idea is to treat the change in state of the board as a function from one moment in time to the next. By recursively subdividing the board, and memoising the state transitions, a lot of computation can be re-used. The same idea is then applied in time, by memoizing entire sequences of state transitions. The result is speedups of the order of a million-fold.&lt;/p&gt;
</description></item><item><title>re: Function Memoization</title><link>http://blogs.msdn.com/wesdyer/archive/2007/01/26/function-memoization.aspx#1548447</link><pubDate>Mon, 29 Jan 2007 01:38:29 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1548447</guid><dc:creator>Judah</dc:creator><description>&lt;p&gt;Thanks for the article, Wes. I enjoyed the Channel 9 video too, very informative. Gets me excited about LINQ. :-)&lt;/p&gt;
&lt;p&gt;FWIW, it's possible to do memoization today in C# 2. It's a bit more verbose without lambdas, of course, but it's do-able nonetheless. See this post for Sriram's how-to:&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://blogs.msdn.com/sriram/archive/2006/01/15/lisp_is_sin.aspx"&gt;http://blogs.msdn.com/sriram/archive/2006/01/15/lisp_is_sin.aspx&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: Function Memoization</title><link>http://blogs.msdn.com/wesdyer/archive/2007/01/26/function-memoization.aspx#1549013</link><pubDate>Mon, 29 Jan 2007 03:53:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1549013</guid><dc:creator>Alex James</dc:creator><description>&lt;p&gt;Great learning resource = Wes Dyer...&lt;/p&gt;</description></item><item><title>Mr</title><link>http://blogs.msdn.com/wesdyer/archive/2007/01/26/function-memoization.aspx#1551555</link><pubDate>Mon, 29 Jan 2007 16:12:23 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1551555</guid><dc:creator>James Jones</dc:creator><description>&lt;p&gt;Thanks for the ongoing functional stuff ...&lt;/p&gt;
&lt;p&gt;I was wondering if you had any opinions on how best to approach ensuring such functions are thread safe?&lt;/p&gt;
</description></item><item><title>re: Function Memoization</title><link>http://blogs.msdn.com/wesdyer/archive/2007/01/26/function-memoization.aspx#1552638</link><pubDate>Mon, 29 Jan 2007 22:41:30 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1552638</guid><dc:creator>wesdyer</dc:creator><description>&lt;p&gt;Damien:&lt;/p&gt;
&lt;p&gt;That is fascinating. &amp;nbsp;I love the game of life and was not aware of that speed up. &amp;nbsp;Thanks for the link.&lt;/p&gt;
&lt;p&gt;Judah:&lt;/p&gt;
&lt;p&gt;You are right. &amp;nbsp;But I would add that not only is it more verbose, it is also uglier and doesn't include type inference.&lt;/p&gt;
&lt;p&gt;James Jones:&lt;/p&gt;
&lt;p&gt;Good question. &amp;nbsp;I'll prep a post about that.&lt;/p&gt;
</description></item><item><title>re: Mr</title><link>http://blogs.msdn.com/wesdyer/archive/2007/01/26/function-memoization.aspx#1559854</link><pubDate>Wed, 31 Jan 2007 02:41:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1559854</guid><dc:creator>wesdyer</dc:creator><description>&lt;p&gt;James:&lt;/p&gt;
&lt;p&gt;As I was thinking about what to write concerning thread safe functions, it seemed that nothing would be particularly helpful without a little more context concerning what problems you are facing.&lt;/p&gt;
&lt;p&gt;Could you describe the specific problems that you are having?&lt;/p&gt;
&lt;p&gt;If you care just to learn general strategies then I could always discuss a few, but this is a topic about which we could write whole books.&lt;/p&gt;
</description></item><item><title>Is C# becoming a functional language?</title><link>http://blogs.msdn.com/wesdyer/archive/2007/01/26/function-memoization.aspx#1564355</link><pubDate>Wed, 31 Jan 2007 13:31:21 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1564355</guid><dc:creator>David's blog</dc:creator><description /></item><item><title>Is C# becoming a functional language?</title><link>http://blogs.msdn.com/wesdyer/archive/2007/01/26/function-memoization.aspx#1564470</link><pubDate>Wed, 31 Jan 2007 13:47:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1564470</guid><dc:creator>David's blog</dc:creator><description /></item><item><title>Is C# becoming a functional language?</title><link>http://blogs.msdn.com/wesdyer/archive/2007/01/26/function-memoization.aspx#1564590</link><pubDate>Wed, 31 Jan 2007 14:29:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1564590</guid><dc:creator>David's blog</dc:creator><description /></item><item><title>re: Function Memoization</title><link>http://blogs.msdn.com/wesdyer/archive/2007/01/26/function-memoization.aspx#1573036</link><pubDate>Thu, 01 Feb 2007 17:09:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1573036</guid><dc:creator>James Jones</dc:creator><description>&lt;p&gt;Hi Wes&lt;/p&gt;
&lt;p&gt;Thank you for the feedback .. it's appreciated.&lt;/p&gt;
&lt;p&gt;I'm very much an OOP minded programmer who is trying very hard to appreciate and adopt a more functional style of programming that will inherently promote thread neutral development. &amp;nbsp;The idea being that my applications scale naturally on multi-processor machines into the future.&lt;/p&gt;
&lt;p&gt;I'm currently working on a system, part of which involves delegating well known interface type instantiation to a factory class. &amp;nbsp;What I'd really like is a way of promoting Singleton type usage of types that do not necessarily implement that pattern themselves. &amp;nbsp;It struck me that your memorize function could be just the ticket to this ... kindof a surrogate singleton.&lt;/p&gt;
&lt;p&gt;Thank you for taking the time to respond and please keep up the excellent posts.&lt;/p&gt;
&lt;p&gt;James&lt;/p&gt;
</description></item><item><title>Community Convergence XX</title><link>http://blogs.msdn.com/wesdyer/archive/2007/01/26/function-memoization.aspx#1580849</link><pubDate>Fri, 02 Feb 2007 10:52:40 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1580849</guid><dc:creator>Charlie Calvert's Community Blog</dc:creator><description>&lt;p&gt;Welcome to the twentieth Community Convergence. I'm Charlie Calvert, the C# Community PM, and this is&lt;/p&gt;</description></item><item><title>Community Convergence XX</title><link>http://blogs.msdn.com/wesdyer/archive/2007/01/26/function-memoization.aspx#1580915</link><pubDate>Fri, 02 Feb 2007 11:10:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1580915</guid><dc:creator>Charlie Calvert's Community Blog</dc:creator><description>&lt;p&gt;Welcome to the twentieth Community Convergence. I'm Charlie Calvert, the C# Community PM, and this is&lt;/p&gt;
</description></item><item><title>re: Function Memoization</title><link>http://blogs.msdn.com/wesdyer/archive/2007/01/26/function-memoization.aspx#1583922</link><pubDate>Fri, 02 Feb 2007 20:41:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1583922</guid><dc:creator>wesdyer</dc:creator><description>&lt;p&gt;James:&lt;/p&gt;
&lt;p&gt;Probably the easiest way to make Memoize thread-safe is to put a lock on map. &amp;nbsp;Like so:&lt;/p&gt;
&lt;p&gt;public static Func&amp;lt;A, R&amp;gt; Memoize&amp;lt;A, R&amp;gt;(this Func&amp;lt;A, R&amp;gt; f)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp;var map = new Dictionary&amp;lt;A, R&amp;gt;();&lt;/p&gt;
&lt;p&gt; &amp;nbsp;return a =&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;lock (map)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;R value;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (map.TryGetValue(a, out value))&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return value;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;value = f(a);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;map.Add(a, value);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return value;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;};&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;This will ensure that the function that is being memoized will only be run once for each set of distinct arguments.&lt;/p&gt;
&lt;p&gt;In my example of the RoboRally game, I actually used function memoization to act as &amp;quot;surrogate singleton&amp;quot;. &amp;nbsp;It isn't really a singleton since there can be one instance per factory instance (unless the factory is static). &amp;nbsp;But that is exactly what I wanted.&lt;/p&gt;
</description></item><item><title>Baby Names, Nameless Keys, and Mumbling</title><link>http://blogs.msdn.com/wesdyer/archive/2007/01/26/function-memoization.aspx#1648801</link><pubDate>Sun, 11 Feb 2007 09:49:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1648801</guid><dc:creator>Yet Another Language Geek</dc:creator><description>&lt;p&gt;Baby Names I recently finished reading Freakonomics . It is a fascinating book about a number of strange&lt;/p&gt;
</description></item><item><title>re: Function Memoization</title><link>http://blogs.msdn.com/wesdyer/archive/2007/01/26/function-memoization.aspx#1671559</link><pubDate>Wed, 14 Feb 2007 01:13:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1671559</guid><dc:creator>Kiryl Batsiukov</dc:creator><description>&lt;p&gt;Great! &lt;/p&gt;
&lt;p&gt;I finaly understood why was Lambda Calculus included in my Informatics Lectures at the university:)&lt;/p&gt;
&lt;p&gt;Thanx for your post&lt;/p&gt;
</description></item><item><title>re: Function Memoization</title><link>http://blogs.msdn.com/wesdyer/archive/2007/01/26/function-memoization.aspx#8452476</link><pubDate>Sat, 03 May 2008 02:04:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8452476</guid><dc:creator>Romain Verdier</dc:creator><description>&lt;p&gt;Pingback from :&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://codingly.com/2008/05/02/optimisation-des-invocations-dynamiques-de-methodes-en-c/"&gt;http://codingly.com/2008/05/02/optimisation-des-invocations-dynamiques-de-methodes-en-c/&lt;/a&gt;&lt;/p&gt;
</description></item></channel></rss>