<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Speedy C#, Part 2: Optimizing Memory Allocations &#8211; Pooling and Reusing Objects</title>
	<atom:link href="http://robpaveza.net/speedy-c-part-2-optimizing-memory-allocations-pooling-and-reusing-objects/feed" rel="self" type="application/rss+xml" />
	<link>http://robpaveza.net/speedy-c-part-2-optimizing-memory-allocations-pooling-and-reusing-objects</link>
	<description>Like with scissors, only more dangerous</description>
	<lastBuildDate>Thu, 10 Jan 2013 18:46:51 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5</generator>
	<item>
		<title>By: Rob Paveza</title>
		<link>http://robpaveza.net/speedy-c-part-2-optimizing-memory-allocations-pooling-and-reusing-objects/comment-page-1#comment-231</link>
		<dc:creator>Rob Paveza</dc:creator>
		<pubDate>Tue, 10 Jan 2012 17:02:05 +0000</pubDate>
		<guid isPermaLink="false">http://robpaveza.net/speedy-c-part-2-optimizing-memory-allocations-pooling-and-reusing-objects#comment-231</guid>
		<description><![CDATA[Hi Anders!

I moved your comment to the analogous post here.  Let me take your comment in two parts.

First, regarding my approach: you&#039;re correct - in this case I&#039;m trading memory for speed.  At any given time we may not be utilizing all of the objects in the Pool.  However, I&#039;m circumventing the need to allocate and deallocate these objects, as well as avoiding the need to compact my GC heap.

Regarding the standard API: the scenario I believe you&#039;re proposing is one in which identical (in meaning) objects are being requested, is this correct?  For example, 25 users each ask for the homepage, which causes 25 identical homepage objects to be retrieved and served up?  In this scenario, it is indeed wasteful; there are obviously better ways to cache these data than by using a simple pool without knowledge of the use of the objects.

As with any tool in a programmer&#039;s toolbelt, you have to consider what and how you&#039;re using the tool.  In the case that I&#039;m describing, I needed to allocate byte arrays to later read, all internally, for my API, and then to surface objects that corresponded to these byte arrays.  I allocated the objects that my API produced, but since I never needed to worry about object identity with the byte arrays (use them then get rid of them), it produced a substantial performance benefit to my application.]]></description>
		<content:encoded><![CDATA[<p>Hi Anders!</p>
<p>I moved your comment to the analogous post here.  Let me take your comment in two parts.</p>
<p>First, regarding my approach: you&#8217;re correct &#8211; in this case I&#8217;m trading memory for speed.  At any given time we may not be utilizing all of the objects in the Pool.  However, I&#8217;m circumventing the need to allocate and deallocate these objects, as well as avoiding the need to compact my GC heap.</p>
<p>Regarding the standard API: the scenario I believe you&#8217;re proposing is one in which identical (in meaning) objects are being requested, is this correct?  For example, 25 users each ask for the homepage, which causes 25 identical homepage objects to be retrieved and served up?  In this scenario, it is indeed wasteful; there are obviously better ways to cache these data than by using a simple pool without knowledge of the use of the objects.</p>
<p>As with any tool in a programmer&#8217;s toolbelt, you have to consider what and how you&#8217;re using the tool.  In the case that I&#8217;m describing, I needed to allocate byte arrays to later read, all internally, for my API, and then to surface objects that corresponded to these byte arrays.  I allocated the objects that my API produced, but since I never needed to worry about object identity with the byte arrays (use them then get rid of them), it produced a substantial performance benefit to my application.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anders Borum</title>
		<link>http://robpaveza.net/speedy-c-part-2-optimizing-memory-allocations-pooling-and-reusing-objects/comment-page-1#comment-230</link>
		<dc:creator>Anders Borum</dc:creator>
		<pubDate>Tue, 10 Jan 2012 10:33:59 +0000</pubDate>
		<guid isPermaLink="false">http://robpaveza.net/speedy-c-part-2-optimizing-memory-allocations-pooling-and-reusing-objects#comment-230</guid>
		<description><![CDATA[Hi Rob,

I came across your article (http://robpaveza.net/speedy-c-part-2-optimizing-memory-allocations-pooling-and-reusing-objects) while searching for ways to optimize C# object references and cache eviction algorithms.

I read your article with interest and was wondering about the Pool class. Over the course of the lifetime of the app domain, unless I&#039;m mistaken, you&#039;re trading time released by less GC overhead with increased memory usage (all those pointers in Pool add up).

Imagine a standard API where a large number of threads each query the API for objects (i.e. enumerate hierarchical relations etc.). The Pool would ensure that if one thread at some point had freed an object, it&#039;d be available for other threads to pick up. If you&#039;ve got 25 concurrent threads working, each asking for the same objects (which would be typical in large scale website scenarios - disregarding output caching here), then each object could potentially allocate up to additional 25x space for pointers.

What kind of frequency are we talking about here, that justifies Pool and not just a ConcurrentDictionary?

Thanks in advance,
Anders Borum (Denmark)]]></description>
		<content:encoded><![CDATA[<p>Hi Rob,</p>
<p>I came across your article (<a href="http://robpaveza.net/speedy-c-part-2-optimizing-memory-allocations-pooling-and-reusing-objects" rel="nofollow">http://robpaveza.net/speedy-c-part-2-optimizing-memory-allocations-pooling-and-reusing-objects</a>) while searching for ways to optimize C# object references and cache eviction algorithms.</p>
<p>I read your article with interest and was wondering about the Pool class. Over the course of the lifetime of the app domain, unless I&#8217;m mistaken, you&#8217;re trading time released by less GC overhead with increased memory usage (all those pointers in Pool add up).</p>
<p>Imagine a standard API where a large number of threads each query the API for objects (i.e. enumerate hierarchical relations etc.). The Pool would ensure that if one thread at some point had freed an object, it&#8217;d be available for other threads to pick up. If you&#8217;ve got 25 concurrent threads working, each asking for the same objects (which would be typical in large scale website scenarios &#8211; disregarding output caching here), then each object could potentially allocate up to additional 25x space for pointers.</p>
<p>What kind of frequency are we talking about here, that justifies Pool and not just a ConcurrentDictionary?</p>
<p>Thanks in advance,<br />
Anders Borum (Denmark)</p>
]]></content:encoded>
	</item>
</channel>
</rss>
