<?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: calloc vs malloc</title>
	<atom:link href="http://boredzo.org/blog/archives/2006-11-26/calloc-vs-malloc/feed" rel="self" type="application/rss+xml" />
	<link>http://boredzo.org/blog/archives/2006-11-26/calloc-vs-malloc</link>
	<description>The personal weblog of Peter Hosey.</description>
	<lastBuildDate>Sun, 14 Mar 2010 12:45:37 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Jens Ayton</title>
		<link>http://boredzo.org/blog/archives/2006-11-26/calloc-vs-malloc/comment-page-1#comment-293645</link>
		<dc:creator>Jens Ayton</dc:creator>
		<pubDate>Fri, 30 Oct 2009 07:36:37 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/archives/2006-11-26/calloc-vs-malloc#comment-293645</guid>
		<description>Just got here from StackOverflow.

One important consequence of fish’s comment is that your timings are completely irrelevant to a program that will actually use (read or write) the memory, because as he says calloc() isn’t actually allocating, let alone clearing, any pages. To get more meaningful timings, you should try reading one byte from each page. I expect calloc() will still win, but by a less ridiculous margin.</description>
		<content:encoded><![CDATA[<p>Just got here from StackOverflow.</p>
<p>One important consequence of fish’s comment is that your timings are completely irrelevant to a program that will actually use (read or write) the memory, because as he says calloc() isn’t actually allocating, let alone clearing, any pages. To get more meaningful timings, you should try reading one byte from each page. I expect calloc() will still win, but by a less ridiculous margin.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Blake C.</title>
		<link>http://boredzo.org/blog/archives/2006-11-26/calloc-vs-malloc/comment-page-1#comment-4377</link>
		<dc:creator>Blake C.</dc:creator>
		<pubDate>Mon, 18 Dec 2006 06:51:12 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/archives/2006-11-26/calloc-vs-malloc#comment-4377</guid>
		<description>I just wrote about something you made me remember-

http://yamacdev.blogspot.com/2006/12/implicit-memcpy3-calls.html

It&#039;s good for a laugh while we&#039;re waiting, I guess :)</description>
		<content:encoded><![CDATA[<p>I just wrote about something you made me remember-</p>
<p><a href="http://yamacdev.blogspot.com/2006/12/implicit-memcpy3-calls.html" rel="nofollow">http://yamacdev.blogspot.com/2006/12/implicit-memcpy3-calls.html</a></p>
<p>It's good for a laugh while we're waiting, I guess :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Hosey</title>
		<link>http://boredzo.org/blog/archives/2006-11-26/calloc-vs-malloc/comment-page-1#comment-3612</link>
		<dc:creator>Peter Hosey</dc:creator>
		<pubDate>Fri, 15 Dec 2006 02:16:35 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/archives/2006-11-26/calloc-vs-malloc#comment-3612</guid>
		<description>Woo — thanks. ☺

The two sets of numbers are from separate runs of the test app — that is, separate processes. (I&#039;m not sure whether that was clear in the post.) Does that change anything? If so, how?</description>
		<content:encoded><![CDATA[<p>Woo — thanks. ☺</p>
<p>The two sets of numbers are from separate runs of the test app — that is, separate processes. (I'm not sure whether that was clear in the post.) Does that change anything? If so, how?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ridiculous_fish</title>
		<link>http://boredzo.org/blog/archives/2006-11-26/calloc-vs-malloc/comment-page-1#comment-3611</link>
		<dc:creator>ridiculous_fish</dc:creator>
		<pubDate>Fri, 15 Dec 2006 01:36:08 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/archives/2006-11-26/calloc-vs-malloc#comment-3611</guid>
		<description>Howdy - fish here.

For large blocks (where &quot;large&quot; is surprisingly small, something like 14 KB) Mac OS X&#039;s default malloc() will always go to the kernel for memory by calling vm_allocate().  vm_allocate() always returns zero-filled pages; otherwise, you might get back a chunk of physical RAM or swap space that had been written to by some root process, and you&#039;d get privileged data.  So for large blocks, we&#039;d expect calloc() and malloc() to perform identically.

Mach will reserve some memory but not physically allocate it until you read or write it.  The pages can also be marked zero filled without having to write zeros to RAM.  But the first time you read from the page, it has to allocate and then zero-fill it.

Your conclusion that calloc is much better than bzero is dead-on.

_fish</description>
		<content:encoded><![CDATA[<p>Howdy - fish here.</p>
<p>For large blocks (where "large" is surprisingly small, something like 14 KB) Mac OS X's default malloc() will always go to the kernel for memory by calling vm_allocate().  vm_allocate() always returns zero-filled pages; otherwise, you might get back a chunk of physical RAM or swap space that had been written to by some root process, and you'd get privileged data.  So for large blocks, we'd expect calloc() and malloc() to perform identically.</p>
<p>Mach will reserve some memory but not physically allocate it until you read or write it.  The pages can also be marked zero filled without having to write zeros to RAM.  But the first time you read from the page, it has to allocate and then zero-fill it.</p>
<p>Your conclusion that calloc is much better than bzero is dead-on.</p>
<p>_fish</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Blake C.</title>
		<link>http://boredzo.org/blog/archives/2006-11-26/calloc-vs-malloc/comment-page-1#comment-3396</link>
		<dc:creator>Blake C.</dc:creator>
		<pubDate>Thu, 14 Dec 2006 04:39:07 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/archives/2006-11-26/calloc-vs-malloc#comment-3396</guid>
		<description>Maybe we should ask Peter Ammon. You may have seen the surprising results he got from his array trials:

http://ridiculousfish.com/blog/archives/2005/12/23/array/

In the current context, I was reminded of this quote: &quot;Say what? I was so surprised by this, I had to rerun my test, but it seems to be right.&quot; Either this cacheing(sp?) issue didn&#039;t exist in his context, or he knew how to avoid it.

It seems even more curious to me that he was testing high level Apple data types(slow), while you&#039;re talking about ANSI stuff(fast). The respective expected delays seem to be reversed...

And thank you for the info- I&#039;m currently scavenging my code for the malloc/bzero happenings and improving them :) Now I&#039;m wondering how I can determine whether this cache thing can also be improved in my code...</description>
		<content:encoded><![CDATA[<p>Maybe we should ask Peter Ammon. You may have seen the surprising results he got from his array trials:</p>
<p><a href="http://ridiculousfish.com/blog/archives/2005/12/23/array/" rel="nofollow">http://ridiculousfish.com/blog/archives/2005/12/23/array/</a></p>
<p>In the current context, I was reminded of this quote: "Say what? I was so surprised by this, I had to rerun my test, but it seems to be right." Either this cacheing(sp?) issue didn't exist in his context, or he knew how to avoid it.</p>
<p>It seems even more curious to me that he was testing high level Apple data types(slow), while you're talking about ANSI stuff(fast). The respective expected delays seem to be reversed...</p>
<p>And thank you for the info- I'm currently scavenging my code for the malloc/bzero happenings and improving them :) Now I'm wondering how I can determine whether this cache thing can also be improved in my code...</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Hosey</title>
		<link>http://boredzo.org/blog/archives/2006-11-26/calloc-vs-malloc/comment-page-1#comment-3393</link>
		<dc:creator>Peter Hosey</dc:creator>
		<pubDate>Thu, 14 Dec 2006 03:39:52 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/archives/2006-11-26/calloc-vs-malloc#comment-3393</guid>
		<description>My guess is that it&#039;s some form of caching that hadn&#039;t caught up yet the first time. The first run of any time trial is always artifically slowed down, no matter what you&#039;re timing. That&#039;s why I always run any time trial at least twice.</description>
		<content:encoded><![CDATA[<p>My guess is that it's some form of caching that hadn't caught up yet the first time. The first run of any time trial is always artifically slowed down, no matter what you're timing. That's why I always run any time trial at least twice.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Blake C.</title>
		<link>http://boredzo.org/blog/archives/2006-11-26/calloc-vs-malloc/comment-page-1#comment-3391</link>
		<dc:creator>Blake C.</dc:creator>
		<pubDate>Thu, 14 Dec 2006 03:23:27 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/archives/2006-11-26/calloc-vs-malloc#comment-3391</guid>
		<description>Thanks for documenting this, I&#039;ve often wondered the same thing. I wonder- what changed between runs to cause the saner results?</description>
		<content:encoded><![CDATA[<p>Thanks for documenting this, I've often wondered the same thing. I wonder- what changed between runs to cause the saner results?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.259 seconds -->
