<?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>Th30z - Coding on the Fly</title>
	<atom:link href="http://th30z.netsons.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://th30z.netsons.org</link>
	<description>Matteo Bertozzi, Objective-C, Cocoa, C, C++, Qt4, iPhone, Mac OS X, Open Moko, Matteo Bertozzi Development</description>
	<lastBuildDate>Sun, 01 Nov 2009 19:04:15 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>OpenGL: Walk Around Camera</title>
		<link>http://th30z.netsons.org/2009/11/opengl-walk-around-camera/</link>
		<comments>http://th30z.netsons.org/2009/11/opengl-walk-around-camera/#comments</comments>
		<pubDate>Sun, 01 Nov 2009 19:04:15 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[OpenGL]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=1302</guid>
		<description><![CDATA[Again, another week spent on OpenGL. I don&#8217;t know why but I cannot stop to experiment with Meshes, Vertexes, Faces and Textures. It&#8217;s too amusing! But Todays, post it&#8217;s just an update of GLData, the small gl data library that I use for my experiments.

The new features, for this update are: Speed-up in GL throughput, and [...]]]></description>
			<content:encoded><![CDATA[<p>Again, another week spent on OpenGL. I don&#8217;t know why but I cannot stop to experiment with Meshes, Vertexes, Faces and Textures. It&#8217;s too amusing! But Todays, post it&#8217;s just an update of GLData, the <em>small gl data library</em> that I use for my experiments.</p>
<p style="text-align: center; "><a href="http://th30z.netsons.org/wp-content/uploads/OpenGLWalkAround.png"><img class="aligncenter size-full wp-image-1301" title="OpenGL Walk Around" src="http://th30z.netsons.org/wp-content/uploads/OpenGLWalkAround.png" alt="OpenGL Walk Around" width="528" height="397" /></a></p>
<p style="text-align: left; ">The new features, for this update are: Speed-up in GL throughput, and Camera. I&#8217;ve adjusted data structure to use directly glVertexPointer() and related gl*Pointer() functions. The main.c file was adjusted to handle direction keys (Up, Down, Left, Right) to allows you to walk in your 3d world, like any First-Person shooter video game.</p>
<p style="text-align: left; ">You can download the GLData <a title="GLData Walk Around Source Code" href="th30z.netsons.org/wp-content/uploads/GLData-WalkAround.zip">Walk Around Source Code it</a>. <em>(Mesh not Included)</em></p>
<p style="text-align: left; "><em>PS: For my Qt followers, and for those which they are waiting for my File-System/Distributed Computational System: I haven&#8217;t forget Qt and the lovely memset(); I&#8217;m just exploring a bit (give me some week), a world that I&#8217;ve completely ignored.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2009/11/opengl-walk-around-camera/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenGL: Meshes and PNG Textures</title>
		<link>http://th30z.netsons.org/2009/10/opengl-meshes-and-png-textures/</link>
		<comments>http://th30z.netsons.org/2009/10/opengl-meshes-and-png-textures/#comments</comments>
		<pubDate>Sun, 25 Oct 2009 11:36:02 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[OpenGL]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=1293</guid>
		<description><![CDATA[Still experimenting with OpenGL, I&#8217;ve played just few games in my life Formula 1 and Tomb Raider. The second one, is more interesting to &#8220;reproduce&#8221; to learn something of OpenGL, meshes and how all of this world works. Following the latest posts, I&#8217;ve added the PNG support to the GLData Sample, so you can now [...]]]></description>
			<content:encoded><![CDATA[<p>Still experimenting with OpenGL, I&#8217;ve played just few games in my life Formula 1 and <a title="Tomb Raider Eidos Interactive" href="http://www.tombraider.com/">Tomb Raider</a>. The second one, is more interesting to &#8220;reproduce&#8221; to learn something of OpenGL, meshes and how all of this world works. Following the latest posts, I&#8217;ve added the PNG support to the GLData Sample, so you can now load BMP and PNG Textures.</p>
<p style="text-align: center;"><a href="http://th30z.netsons.org/wp-content/uploads/OpenGL-Meshes.png"><img class="aligncenter size-full wp-image-1292" title="OpenGL Meshes" src="http://th30z.netsons.org/wp-content/uploads/OpenGL-Meshes.png" alt="OpenGL Meshes" width="560" height="393" /></a></p>
<p>The Source Code is available here: <a href="http://th30z.netsons.org/wp-content/uploads/gldata-v3.zip">GL Data Source Code</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2009/10/opengl-meshes-and-png-textures/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenGL meets Blender: Meshes and Textures</title>
		<link>http://th30z.netsons.org/2009/10/opengl-meets-blender-meshes-and-textures/</link>
		<comments>http://th30z.netsons.org/2009/10/opengl-meets-blender-meshes-and-textures/#comments</comments>
		<pubDate>Sat, 17 Oct 2009 15:04:25 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[Blender]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=1275</guid>
		<description><![CDATA[As you can see from the bigger Screenshot below, Today is time to put some characters on the OpenGL stage. And the two guys below are two of the characters of Yo Frankie! (http://www.yofrankie.org/). Following the preview post I&#8217;ve extended my GLData Library adding support for Textures and using another source format as Input File, [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">As you can see from the bigger Screenshot below, Today is time to put some characters on the OpenGL stage. And the two guys below are two of the characters of <strong>Yo Frankie!</strong> (<a title="Yo Frankie!" href="http://www.yofrankie.org/">http://www.yofrankie.org/</a>). Following the preview post I&#8217;ve extended my GLData Library adding support for Textures and using another source format as Input File, I&#8217;ve also made a simple Blender-Export Script that allows you to easily export blender meshes with textures, vertexes and faces.</p>
<p style="text-align: center;"><a href="http://th30z.netsons.org/wp-content/uploads/OpenGL-Blender.png"><img class="aligncenter size-full wp-image-1276" title="OpenGL Blender Yo Frankie Chars" src="http://th30z.netsons.org/wp-content/uploads/OpenGL-Blender.png" alt="OpenGL Blender Yo Frankie Chars" width="588" height="422" /></a></p>
<p style="text-align: left;">If you are, as me, fan of black and white command lines, The result is stunning. And there&#8217;re just few lines of code. The code can be downloaded from here: <a title="GLData Blender Source Code" href="http://th30z.netsons.org/wp-content/uploads/gldata-blender.tar.bz2">GLData Blender Source Code</a>. It contains the source code, textures, meshes and the Blender Export Script.</p>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2009/10/opengl-meets-blender-meshes-and-textures/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenGL: Gts Format, Lights and Cameras</title>
		<link>http://th30z.netsons.org/2009/10/opengl-gts-format-lights-and-cameras/</link>
		<comments>http://th30z.netsons.org/2009/10/opengl-gts-format-lights-and-cameras/#comments</comments>
		<pubDate>Sun, 11 Oct 2009 10:27:40 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[Gts]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=1258</guid>
		<description><![CDATA[During my work, I&#8217;ve found an interesting library GNU Triangulated Surface Library (http://gts.sourceforge.net/) that does, some nice things, like Constrained Delaunay triangulations. But what I was really searching today are just meshes to use in my OpenGL experiments. And there&#8217;re a some GTS samples available on the GTS website.

The screenshot above represents a GTS sample [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">During my work, I&#8217;ve found an interesting library <em>GNU Triangulated Surface Library</em> (<a title="GNU Triangulation Surface Library" href="http://gts.sourceforge.net/">http://gts.sourceforge.net/</a>) that does, some nice things, like Constrained Delaunay triangulations. But what I was really searching today are just meshes to use in my OpenGL experiments. And there&#8217;re a some GTS samples available on the <a title="GTS Samples" href="http://gts.sourceforge.net/samples.html">GTS website</a>.</p>
<p style="text-align: center; "><a href="http://th30z.netsons.org/wp-content/uploads/GlDataGts.png"><img class="aligncenter size-full wp-image-1259" title="GlData Gts Sample" src="http://th30z.netsons.org/wp-content/uploads/GlDataGts.png" alt="GlData Gts Sample" width="576" height="405" /></a></p>
<p style="text-align: left;">The screenshot above represents a GTS sample shape with a simple light effect. Just few lines of code to do it. But what I&#8217;m interested in, is create a simple way to load GTS file format, and below you can see the code.</p>
<p><code></p>
<pre>
void drawObject (const char *gts_shape_filename) {
    GLDataGts *gts;

    gts = glDataGtsAlloc();
    if (glDataGtsRead(gts, gts_shape_filename)) {
        GLDataSurface *surface;
        GLDataUInt i, count;
        GLDataTriangle *t;

        /* The Surface is an array of Triangles */
        surface = glDataGtsSurface(gts, NULL);
        count = glDataSurfaceCount(surface);
        for (i = 0; i &lt; count; ++i) {
            t = glDataSurfaceGet(surface, i);

            glBegin(GL_LINE_LOOP);
            glVertex3f(t-&gt;p1-&gt;x, t-&gt;p1-&gt;y, t-&gt;p1-&gt;z);
            glVertex3f(t-&gt;p2-&gt;x, t-&gt;p2-&gt;y, t-&gt;p2-&gt;z);
            glVertex3f(t-&gt;p3-&gt;x, t-&gt;p3-&gt;y, t-&gt;p3-&gt;z);
            glEnd();
        }
    }

    glDataGtsRelease(gts);
}
</pre>
<p></code><br />
The Source code is available here <a href="http://th30z.netsons.org/wp-content/uploads/GLDataGts.zip">GLDataGts Source Code</a>, and main.c contains a few comment lines that explain how to compile and run. Check the keyboardHandler() function to learn how to interact with the OpenGL camera and lights.</p>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2009/10/opengl-gts-format-lights-and-cameras/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenCL is for Everyone!</title>
		<link>http://th30z.netsons.org/2009/10/opencl-is-for-everyone/</link>
		<comments>http://th30z.netsons.org/2009/10/opencl-is-for-everyone/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 17:33:53 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[OpenCL]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=1250</guid>
		<description><![CDATA[Last night I had a terrible nightmare, where all the apple/mac bloggers says &#8220;This app cannot be use used with older macs because it uses OpenCL, so you need the newest NVidia…&#8221;
..Fortunately, was just a nightmare. Everyone can use OpenCL, old macs (as my macbook) cannot use GPU, and cannot run faster, but OpenCL code [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://th30z.netsons.org/wp-content/uploads/OpenCL.jpg"><img src="http://th30z.netsons.org/wp-content/uploads/OpenCL.jpg" alt="OpenCL" title="OpenCL" width="137" height="147" class="alignright size-full wp-image-1253" /></a>Last night I had a terrible nightmare, where all the apple/mac bloggers says &#8220;This app cannot be use used with older macs because it uses OpenCL, so you need the newest NVidia…&#8221;</p>
<p>..Fortunately, was just a nightmare. Everyone can use OpenCL, old macs (as my macbook) cannot use GPU, and cannot run faster, but OpenCL code can run on every machine.</p>
<p>You (as developer) need just to keep in mind to get Device in this way. So, if you haven&#8217;t the latest NVidia you can still use, as always, CPU.<br />
<code></p>
<pre>
err = clGetDeviceIDs(NULL, CL_DEVICE_TYPE_GPU, 1, &#038;device_id, NULL);
if (err != CL_SUCCESS)
    err = clGetDeviceIDs(NULL, CL_DEVICE_TYPE_CPU, 1, &#038;device_id, NULL);
</pre>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2009/10/opencl-is-for-everyone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[TIP] XCode Header Search Path</title>
		<link>http://th30z.netsons.org/2009/09/tip-xcode-header-search-path/</link>
		<comments>http://th30z.netsons.org/2009/09/tip-xcode-header-search-path/#comments</comments>
		<pubDate>Sat, 26 Sep 2009 10:26:08 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[XCode]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=1243</guid>
		<description><![CDATA[For many of you, this sounds like a stupid thing. But for those that just use gcc -I from command line, can be a pain find how to do it.
So, the problem is. How can I specify my Include path in XCode (gcc -I./mypath).

Tap on your project target, and click &#8220;Get Info&#8220;, tap on &#8220;Build&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>For many of you, this sounds like a stupid thing. But for those that just use gcc -I from command line, can be a pain find how to do it.</p>
<p>So, the problem is. How can I specify my Include path in XCode (gcc -I./mypath).</p>
<p style="text-align: center;"><a href="http://th30z.netsons.org/wp-content/uploads/XCode-SearchHeaderPath1.png"><img class="aligncenter size-full wp-image-1245" title="XCode Search Header Path" src="http://th30z.netsons.org/wp-content/uploads/XCode-SearchHeaderPath1.png" alt="XCode Search Header Path" width="566" height="279" /></a></p>
<p>Tap on your project target, and click &#8220;<strong>Get Info</strong>&#8220;, tap on &#8220;<strong>Build</strong>&#8221; tab and search &#8220;Path&#8221; as showed in the figure above. Then click on the &#8220;<strong>Header Search Paths</strong>&#8221; options and add your favorite include paths for selected target.</p>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2009/09/tip-xcode-header-search-path/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>File-System: Delayed Allocation, fsync() solution</title>
		<link>http://th30z.netsons.org/2009/09/file-system-delayed-allocation-fsync-solution/</link>
		<comments>http://th30z.netsons.org/2009/09/file-system-delayed-allocation-fsync-solution/#comments</comments>
		<pubDate>Sat, 19 Sep 2009 09:51:07 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Unix C]]></category>
		<category><![CDATA[File-System]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=1229</guid>
		<description><![CDATA[Last week on LWN Valerie Aurora as posted a great article (as always) POSIX v. reality: A position on O_PONIES. http://lwn.net/Articles/351422/.
fsync() is often more expensive than it absolutely needs to be.  The easiest way to implement it is to force out every outstanding write to the file system, regardless of whether it is a [...]]]></description>
			<content:encoded><![CDATA[<p>Last week on LWN <a title="Valerie Aurora" href="http://valerieaurora.org/">Valerie Aurora</a> as posted a great article (as always) POSIX v. reality: A position on O_PONIES. <a title="POSIX v. reality: A position on O_PONIES" href="http://lwn.net/Articles/351422/">http://lwn.net/Articles/351422/</a>.</p>
<p><em><code>fsync()</code> is often more expensive than it absolutely needs to be.  The easiest way to implement <code>it</code> is to force out every outstanding write to the file system, regardless of whether it is a journaling file system, a COW file system, or a file system with no crash recovery mechanism whatsoever.  This is because it is very difficult to map backward from a given file to the dirty file system blocks needing to be written to disk in order to create a consistent file system containing those changes.  For example, the block containing the bitmap for newly allocated file data blocks may also have been changed by a later allocation for a different file, which then requires that we also write out the indirect blocks pointing to the data for that second file, which changes another bitmap block&#8230; When you solve the problem of tracing specific dependencies of any particular write, you end up with the complexity of <a href="http://lwn.net/Articles/339337/">soft updates</a>.  No surprise then, that most file systems take the brute force approach, with the result that <code>fsync()</code> commonly takes time proportional to all outstanding writes to the file system.</em></p>
<p>Thinking for a while&#8230; Is not hard to implement fsync(), to flush just one file using <a title="Delayed Allocation" href="http://en.wikipedia.org/wiki/Allocate-on-flush">Delayed Allocation</a> (Allocate on Flush). We&#8217;ve all new data in memory, and old data stay on its block. So, modification in place means that you&#8217;ve just to flush blocks. Append means that you need to allocate something.<br />
<a href="http://th30z.netsons.org/wp-content/uploads/RaleighFs-InMem.png"><img class="aligncenter size-full wp-image-1232" title="RaleighFS in Memory Structure" src="http://th30z.netsons.org/wp-content/uploads/RaleighFs-InMem.png" alt="RaleighFS in Memory Structure" width="581" height="435" /></a>The image above, is a little bit old, but it&#8217;s the original idea of the RaleighFS in Memory Structure. There&#8217;re general information like super-block, bad blocks list and free blocks lis, current cache size and some other things. But today I&#8217;m focusing on <strong>Block Cache</strong> and <strong>Write Items Cache</strong>.</p>
<p>When you open a file, you load its metadata in memory then when you need file content you load it in the Block Cache. RaleighFS data block contains the File Key, so you can easily find blocks with specified key, but also you can easily find your file blocks using pointers.</p>
<p>So, why is easy to fsync() only the specified file with Delayed Allocation:</p>
<ul>
<li>Modification in place, requires just a scan of the block cache to find what blocks are to flush (and obviously metadata)</li>
<li>Append to file, has all new data in memory and there&#8217;re no Modification to B*Tree(s) or Free blocks until you flush something.</li>
<li>Remove is just a command, and when fsync() is called all the delete operation on B*Tree(s) and list will take places.</li>
</ul>
<p>But remember, syncing just one file is not a good idea, Trust your File-System&#8217;s flush policy!</p>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2009/09/file-system-delayed-allocation-fsync-solution/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Grand Central Dispatch: First Look</title>
		<link>http://th30z.netsons.org/2009/09/grand-central-dispatch-first-look/</link>
		<comments>http://th30z.netsons.org/2009/09/grand-central-dispatch-first-look/#comments</comments>
		<pubDate>Sun, 06 Sep 2009 05:00:32 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Grand Central Dispatch]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Threading]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=1202</guid>
		<description><![CDATA[In the last years I&#8217;ve always used a &#8220;parallel task&#8221; approach foreach loops that I&#8217;ve in the code, not always to speedup but even to clean-up the code. How to do it? Wrapping threads and Thread Pool like in this C# Parallel Forech Code.
Snow Leopard has introduced a new BSD-level infrastructure, with simple and efficient [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://en.wikipedia.org/wiki/Grand_Central_Dispatch"><img src="http://th30z.netsons.org/wp-content/uploads/GDC-Logo.png" alt="Mac OS X Grand Central Dispatch" title="Mac OS X Grand Central Dispatch" width="118" height="106" class="alignright size-full wp-image-1207" /></a>In the last years I&#8217;ve always used a &#8220;parallel task&#8221; approach foreach loops that I&#8217;ve in the code, not always to speedup but even to clean-up the code. <em>How to do it? Wrapping threads and Thread Pool like in this <a href="http://th30z.netsons.org/2008/12/c-parallel-foreach-using-thread-pool/">C# Parallel Forech Code</a></em>.</p>
<p><strong>Snow Leopard</strong> has introduced a new BSD-level infrastructure, with simple and efficient API to do this job. Here a little usage preview.</p>
<p><strong>Block objects</strong> are a C-based language feature that you can use in your C, Objective-C, and C++ code. Blocks make it easy to define a self-contained unit of work. Blocks are something like Actions (delegate {}) in C#. <em>Very useful to embed function in loops.</em></p>
<p>Blocks looks like a &#8220;private&#8221; function pointer, but you can access to the &#8220;parent&#8221; vars. (<em>If you&#8217;re a Python coder, you&#8217;ve exactly the same thing</em>).<br />
<code></p>
<pre>
/* Blocks in Python...
 * def main():
 *    a = 10
 *    def test(k):
 *        print a, k
 *    test(128)
 */
int main (int argc, const char *argv[]) {
  int a = 12;

  void (^test_block) (int) = ^(int k) {
    printf("A Block: PARENT(%d) ARG(%d)\n", a, k);
  };

  test_block(128);

  return 0;
}
</pre>
<p></code></p>
<p>The <strong>GCD</strong> queue API provides <strong>dispatch queues</strong> from which threads take tasks to be executed. Because the threads are managed by GCD, Mac OS X can optimize the number of threads based upon available memory, number of currently active CPU cores, and so on. This shifts a great deal of the burden of power and resource management to the operating system itself, freeing your application to focus on the actual work to be accomplished.<br />
<code></p>
<pre>
#include &lt;dispatch/dispatch.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;

#define ITEM_VMIN       (1)
#define ITEM_VMAX       (200)
#define NR_ITEMS        (100)

static void __fill_item (void *items, size_t n) {
  int *i_items = (int *)items;
  i_items[n] = (ITEM_VMIN + (int)(ITEM_VMAX * ((double)rand() / RAND_MAX)));
}

static void __work_on_item (void *items, size_t n) {
  int *i_items = (int *)items;
  i_items[n] *= 100;  /* Do some Computation on this Item */
}

int main (int argc, const char *argv[]) {
  dispatch_queue_t queue;
  int data[NR_ITEMS];

  /* Get Global Dispatch Queue */
  queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

  /* Initialize data Elements, and run computation on each element */
  dispatch_apply_f(NR_ITEMS, queue, data, __fill_item);
  dispatch_apply_f(NR_ITEMS, queue, data, __work_on_item);

  /* Brief review of the items */
  dispatch_apply(NR_ITEMS, queue, ^(size_t n) {
    printf(&quot;Results: Item %lu = %d\n&quot;, n, data[n]);
  });

  return 0;
}
</pre>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2009/09/grand-central-dispatch-first-look/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>File-System and Data Block Back Reference</title>
		<link>http://th30z.netsons.org/2009/09/file-system-and-data-block-back-reference/</link>
		<comments>http://th30z.netsons.org/2009/09/file-system-and-data-block-back-reference/#comments</comments>
		<pubDate>Sun, 06 Sep 2009 04:50:45 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[File-System]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=1221</guid>
		<description><![CDATA[While I&#8217;m thinking and waiting for suggestions on how to improve my file-system block cache algorithm, I&#8217;ve decided to apply some changes to the Raleigh File-System Format (source code is not published yet).
Following the ideas of Valerie Aurora of Repair-driven File System Design, I&#8217;ve decided to add for each block (B*Tree and Data blocks) an [...]]]></description>
			<content:encoded><![CDATA[<p>While I&#8217;m thinking and waiting for suggestions on how to improve my file-system <a title="Block Cache Algorithm" href="http://th30z.netsons.org/2009/08/block-cache-algorithm/">block cache algorithm</a>, I&#8217;ve decided to apply some changes to the Raleigh File-System Format (<em>source code is not published yet</em>).</p>
<p>Following the ideas of <a title="Valerie Aurora" href="http://valerieaurora.org/">Valerie Aurora</a> of <a href="review/repair.pdf">Repair-driven File System Design</a>, I&#8217;ve decided to add for each block (B*Tree and Data blocks) an head that contains a <strong>Magic Number</strong> and a <strong>CRC Sum</strong> of the block. In this way you can easily identify what kind of block you&#8217;ve peeked without scanning all metadata. Another step is to add a back reference (or back pointer) to the data block, in this way you can easily jump back to it&#8217;s the extent block (and obviously to its OID) so you can easily understand what is the Object owner of this block and you can easily swap two blocks reading at most 4 blocks (2 Data and 2 Extends).</p>
<p>Another idea stolen from Valerie is to <strong>double the metadata blocks</strong> with a COW-like approach, as explained in this paper &#8220;<a title="Double the Metadata Double the Fun A COW-like Approach to File System Consistency" href="http://valerieaurora.org/review/doublefs.pdf">Double the Metadata, Double the Fun: A COW-like Approach to FS Consistency</a>&#8220;, really useful for personal file-systems but maybe less in a distributed file-system. I&#8217;m working on it adding only as an mkfs option.</p>
<p><em>When the source Code will be online? I don&#8217;t know.. I&#8217;ve less time to work on it. Maybe at the end of this year I&#8217;ll publish the File-System and the Distributed System (explained some posts ago).</em></p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 47px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Double the Metadata, Double the Fun: A COW-like Approach to File</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 47px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">System Consistency<span style="background-color: #ffffff;">&#8220;</span></div>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2009/09/file-system-and-data-block-back-reference/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mac OS X 10.6 Snow Leopard</title>
		<link>http://th30z.netsons.org/2009/09/mac-os-x-10-6-snow-leopard/</link>
		<comments>http://th30z.netsons.org/2009/09/mac-os-x-10-6-snow-leopard/#comments</comments>
		<pubDate>Sat, 05 Sep 2009 09:59:49 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Screenshots]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=1195</guid>
		<description><![CDATA[It&#8217;s finally here.  Mac OS X Snow Leopard, The world&#8217;s most advanced operating system. Finely tuned.

Ok, It&#8217;s one week later&#8230; but I&#8217;ve installed it just right now. Maybe tomorrow morning an usage example of Grand Central Dispatch.
]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s finally here.  <a title="Apple Mac OS X Snow Leopard" href="http://www.apple.com/mac">Mac OS X Snow Leopard</a>, <em>The world&#8217;s most advanced operating system. Finely tuned.</em></p>
<p style="text-align: left;"><a href="http://th30z.netsons.org/wp-content/uploads/SnowLeopard-01.png"><img class="aligncenter size-large wp-image-1194" title="Mac OS X 10.6 Snow Leopard" src="http://th30z.netsons.org/wp-content/uploads/SnowLeopard-01-1024x640.png" alt="Mac OS X 10.6 Snow Leopard" width="553" height="346" /></a><br />
Ok, It&#8217;s one week later&#8230; but I&#8217;ve installed it just right now. Maybe tomorrow morning an usage example of <a title="Grand Central Dispatch" href="http://en.wikipedia.org/wiki/Grand_Central_Dispatch">Grand Central Dispatch</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2009/09/mac-os-x-10-6-snow-leopard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone: Voice Mill</title>
		<link>http://th30z.netsons.org/2009/08/iphone-voice-mill/</link>
		<comments>http://th30z.netsons.org/2009/08/iphone-voice-mill/#comments</comments>
		<pubDate>Sun, 30 Aug 2009 04:30:13 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Audio]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=1175</guid>
		<description><![CDATA[Yesterday I&#8217;ve played a bit with AVAudioRecorder, and this is a very small and funny example.
The main Idea is to create something like a wind mill that works with voice instead of wind.

The code below shows you how to record something. Then with the updateMeters() and peakPowerForChannel() you can extract the audio &#8220;noise&#8221;.


NSURL *url = [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I&#8217;ve played a bit with AVAudioRecorder, and this is a very small and funny example.<br />
The main Idea is to create something like a wind mill that works with voice instead of wind.</p>
<p style="text-align: center;"><object width="575" height="360" data="http://th30z.netsons.org/wp-content/uploads/VoiceMillVideo.swf" type="application/x-shockwave-flash"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://th30z.netsons.org/wp-content/uploads/VoiceMillVideo.swf" /><param name="allowfullscreen" value="true" /></object></p>
<p>The code below shows you how to record something. Then with the <em>updateMeters()</em> and <em>peakPowerForChannel()</em> you can extract the audio &#8220;noise&#8221;.<br />
<code></p>
<pre>
NSURL *url = [NSURL fileURLWithPath:@&quot;/dev/null&quot;];
NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:
    [NSNumber numberWithFloat:44100.0], AVSampleRateKey,
    [NSNumber numberWithInt:kAudioFormatAppleLossless], AVFormatIDKey,
    [NSNumber numberWithInt:1], AVNumberOfChannelsKey,
    [NSNumber numberWithInt:AVAudioQualityLow], AVEncoderAudioQualityKey,
    nil];

NSError *error;
recorder = [[AVAudioRecorder alloc] initWithURL:url
            settings:settings error:&amp;error];
if (recorder) {
    [recorder prepareToRecord];
    recorder.meteringEnabled = YES;
    [recorder record];
    ...
}
</pre>
<p></code><br />
The SWF Video is available here <a href="http://th30z.netsons.org/wp-content/uploads/VoiceMillVideo.swf">Voice Mill Video</a>.<br />
The Source Code is available here <a href="http://th30z.netsons.org/wp-content/uploads/Cocoa-VoiceMill.zip">Cocoa Voice Mill Source Code</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2009/08/iphone-voice-mill/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Block Cache Algorithm</title>
		<link>http://th30z.netsons.org/2009/08/block-cache-algorithm/</link>
		<comments>http://th30z.netsons.org/2009/08/block-cache-algorithm/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 18:44:37 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[Cache]]></category>
		<category><![CDATA[File-System]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=1163</guid>
		<description><![CDATA[I need to replace my old filesystem cache algorithm with something more new and efficient. The old one is based on LRU/LFU algorithm. There&#8217;s a queue of cached blocks and an Hashtable to speedup block lookup.


struct blkcache_buf {
    struct blkcache_buf *  next;    /* Next Queue Item */
  [...]]]></description>
			<content:encoded><![CDATA[<p>I need to replace my old filesystem cache algorithm with something more new and efficient. The old one is based on LRU/LFU algorithm. <em>There&#8217;s a queue of cached blocks and an Hashtable to speedup block lookup.</em><br />
<code></p>
<pre>
struct blkcache_buf {
    struct blkcache_buf *  next;    /* Next Queue Item */
    struct blkcache_buf *  prev;    /* Prev Queue Item */
    struct blkcache_buf *  hash;    /* Next Item with the same hash */

    xuint16_t              count;   /* Retain count */
    xxx_block_t            block;   /* Cached Block */
};

typedef struct {
    struct blkcache_buf ** buf_hash;        /* Bufs Hashtable */
    xuint16_t              buf_hash_size;   /* Bufs Hashtable Size */
    xuint16_t              buf_used;        /* Bufs in use */

    struct blkcache_buf *  head;            /* Head of the Bufs Queue */
    struct blkcache_buf *  tail;            /* Tail of the Bufs Queue */

    xxx_device_t *         device;          /* Block Device used for I/O */
} xxx_blkcache_t;
</pre>
<p></code><br />
Above, you can see the cache data structure and below the core of the cache Algorithm.<br />
<code></p>
<pre>
#define BUFHASH(cache, blocknr)     ((blocknr) % (cache)-&gt;buf_hash_size)

xxx_block_t *xxx_blkcache_read (xxx_blkcache_t *cache,
                                xxx_blkptr_t blocknr)
{
    struct blkcache_buf *buf;
    xuint16_t hash_index;

    /* Scan the hash chain for block */
    hash_index = BUFHASH(cache, blocknr);
    if ((buf = __blkcache_find(cache, blocknr, hash_index)) != NULL) {
        buf-&gt;count++;

        /* Move Buf far from head */
        __blkcache_buf_shift(cache, buf);

        return(&amp;(buf-&gt;block));
    }

    /* Cache is Full, Remove one Item */
    if ((cache-&gt;buf_used + 1) &gt; cache-&gt;buf_hash_size) {
        /* All buffers are in use */
        if (cache-&gt;head-&gt;count &gt; 0)
            return(NULL);

        /* Remove Least-Frequently Used */
        buf = __blkcache_remove_lfu(cache);
        cache-&gt;buf_used--;
    }

    /* Desidered block is not on available chain, Read It! */
    if ((buf = __blkcache_buf_alloc(cache, buf, blocknr)) == NULL)
        return(NULL);

    /* Add One Use, Block cannot be removed */
    buf-&gt;count++;

    /* Go get the requested block unless searching or prefetching. */
    __blkcache_readwrite(cache, buf, RFALSE);

    /* Update Cache Hash */
    cache-&gt;buf_used++;
    buf-&gt;hash = cache-&gt;buf_hash[hash_index];
    cache-&gt;buf_hash[hash_index] = buf;

    /* Update Cache Queue */
    if (cache-&gt;head == NULL) {
        cache-&gt;head = cache-&gt;tail = buf;
    } else {
        buf-&gt;prev = cache-&gt;tail;
        cache-&gt;tail-&gt;next = buf;
        cache-&gt;tail = buf;
    }

    return(&amp;(buf-&gt;block));
}
</pre>
<p></code><br />
You can download a demo implementation here: <a href="http://th30z.netsons.org/wp-content/uploads/lru-block-cache.c" title="LRU Cache Source Code">lru-block-cache.c</a>, but <em>I&#8217;m waiting some ideas or suggestions to improve (or change radically) the Cache Algorithm. Thanks in advance!</em></p>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2009/08/block-cache-algorithm/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>[TIP] Generic Binary Format</title>
		<link>http://th30z.netsons.org/2009/08/tip-generic-binary-format/</link>
		<comments>http://th30z.netsons.org/2009/08/tip-generic-binary-format/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 11:26:31 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Networking]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Binary Format]]></category>
		<category><![CDATA[Protocols]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=1156</guid>
		<description><![CDATA[I Love use Binary formats, instead of XML, and JSON. Here is my Generic Binary Format for data transmissions or serializations. Data is composed by three blocks. The first one 1byte that describe all information about the object, like &#8220;is a single Int object&#8221; or &#8220;is a list&#8221;, then tells you the second block length. [...]]]></description>
			<content:encoded><![CDATA[<p>I Love use Binary formats, instead of XML, and JSON. Here is my Generic Binary Format for data transmissions or serializations. Data is composed by three blocks. The first one 1byte that describe all information about the object, like &#8220;is a single Int object&#8221; or &#8220;is a list&#8221;, then tells you the second block length. The second block contains the size of the third block (The Data-Block) or the Number of Items in List.</p>
<p><a href="http://th30z.netsons.org/wp-content/uploads/Generic-Binary-Format.png"><img class="aligncenter size-full wp-image-1155" title="Generic Binary Format" src="http://th30z.netsons.org/wp-content/uploads/Generic-Binary-Format.png" alt="Generic Binary Format" width="577" height="289" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2009/08/tip-generic-binary-format/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[TIP] Generic Key Comparer</title>
		<link>http://th30z.netsons.org/2009/08/tip-generic-key-comparer/</link>
		<comments>http://th30z.netsons.org/2009/08/tip-generic-key-comparer/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 17:49:37 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[Distributed Computation]]></category>
		<category><![CDATA[Key Comparer]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=1133</guid>
		<description><![CDATA[I&#8217;m back to code on my &#8220;Cloud&#8221; FileSystem, and distributed tools. And here is a little tip.
When you&#8217;re working on Data, probably you store it as a Key-Value Pair on a BTree or something similar, and maybe this key is an aggregation of information&#8230; Maybe you&#8217;ve one bit of flag, N bytes of ParentKey, and [...]]]></description>
			<content:encoded><![CDATA[<p><em>I&#8217;m back to code on my &#8220;Cloud&#8221; FileSystem, and distributed tools. And here is a little tip.</em></p>
<p>When you&#8217;re working on Data, probably you store it as a Key-Value Pair on a BTree or something similar, and maybe this key is an aggregation of information&#8230; Maybe you&#8217;ve one bit of flag, N bytes of ParentKey, and others&#8230;</p>
<p>Now, the problem is&#8230; How can a &#8220;foreign&#8221; server sort correctly my keys? The solution is to send to the server the information on how to sort.. or a method to do it&#8230; but today, I&#8217;m focusing on the first one.</p>
<p><a href="http://th30z.netsons.org/wp-content/uploads/generic-key-comparer.png"><img class="aligncenter size-full wp-image-1138" title="Generic Key" src="http://th30z.netsons.org/wp-content/uploads/generic-key-comparer.png" alt="Generic Key" width="428" height="133" /></a></p>
<p>The code below show an implementation in Python of the Generic Key Comparer. At the end of the source code you can find an usage example. The Full Source Code is available here. <a href="http://th30z.netsons.org/wp-content/uploads/generic-key-comparer.py">Generic Key Comparer Source Code</a>.<br />
<code></p>
<pre>
def __indexOfOne(data, tokens, offset):
   for i in xrange(offset, len(data)):
   if data[i] in tokens:
      return i
   return -1

def rawComparer(data1, data2, comparer):
   typeIds = [ 's', 'u', 'c', 'i', 'f', 'x' ]
   pyBinMap = {
      ('u', 1): 'B', ('u', 2): 'H', ('u', 4):'L', ('u', 8):'Q',
      ('i', 1): 'b', ('i', 2): 'h', ('i', 4):'l', ('i', 8):'q',
      ('f', 4): 'f', ('f', 8): 'd'
   }

   p = i = 0
   while i &lt; len(comparer):
      nextIdx = __indexOfOne(comparer, typeIds, i + 1)
      if (nextIdx &lt; 0): nextIdx = len(comparer)

      format = None
      length = 1 if (i + 1) == nextIdx else int(comparer[i+1:nextIdx])
      if comparer[i] == 's':
         format = str(length) + 's'
      elif comparer[i] == 'c':
         format = 'c'
      elif (comparer[i], length) in pyBinMap:
         format = pyBinMap[(comparer[i], length)]         

      if format != None:
         d1 = struct.unpack(format, data1[p:p+length])[0]
         d2 = struct.unpack(format, data2[p:p+length])[0]

         if d1 &lt; d2:
            return -1
         elif d1 &gt; d2:
            return 1         

      p += length
      i = nextIdx
   return 0

# Usage Example
if __name__ == '__main__':
  data1 = struct.pack('4sLch', 'test', 10, 'A', -3)
  data2 = struct.pack('4sLch', 'test', 10, 'A', -3)
  print 'Equal (test 10 A -3)', rawComparer(data1, data2, 's4u4ci2')

  data1 = struct.pack('4sLch', 'test', 10, 'A', 1)
  data2 = struct.pack('4sLch', 'test', 10, 'A', 0)
  print '(test 10 A 1) > (test 10 A 0)', rawComparer(data1, data2, 's4u4ci2')

  data1 = struct.pack('4sLch', 'test', 10, 'A', 0)
  data2 = struct.pack('4sLch', 'test', 10, 'A', 1)
  print '(test 10 A 0) < (test 10 A 1)', rawComparer(data1, data2, 's4u4ci2')
</pre>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2009/08/tip-generic-key-comparer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unified Notification Service: Avoid The Wheel Reinvention</title>
		<link>http://th30z.netsons.org/2009/08/unified-notification-service-avoid-the-wheel-reinvention/</link>
		<comments>http://th30z.netsons.org/2009/08/unified-notification-service-avoid-the-wheel-reinvention/#comments</comments>
		<pubDate>Fri, 07 Aug 2009 04:43:31 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Networking]]></category>
		<category><![CDATA[Notification Service]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=1118</guid>
		<description><![CDATA[Every programmer loves to reinvent the wheel, and reinventing the wheel is still my primary hobby. Sometimes you need to reimplement a Network protocol to use with your favorite language/library, sometimes is only for fun, but if you&#8217;re in the Business World maybe is &#8220;better&#8221; (faster) to use one of the thousand existing libraries.
In the [...]]]></description>
			<content:encoded><![CDATA[<p>Every programmer loves to reinvent the wheel, and reinventing the wheel is still my primary hobby. Sometimes you need to reimplement a Network protocol to use with your favorite language/library, sometimes is only for fun, but if you&#8217;re in the Business World maybe is &#8220;better&#8221; (faster) to use one of the thousand existing libraries.</p>
<p>In the most cases you need to reimplement a Protocol to embed it in your application, and sometimes you have to reimplement two/three protocols that does the same job like IM Protocols (XMPP, AIM, Yahoo&#8230;).</p>
<p>A better solution, that avoid you to reinvent the wheel is to use an existent library to handle the protocol(s) that you need, and build an Abstract Interface, with your data format, that allows you to use a generic way to communicate between various provider. Below you can find a graphical example of what I mean.</p>
<p><a href="http://th30z.netsons.org/wp-content/uploads/UnifiedNotificationService.png"><img class="aligncenter size-full wp-image-1119" title="Unified Notification Service" src="http://th30z.netsons.org/wp-content/uploads/UnifiedNotificationService.png" alt="Unified Notification Service" width="513" height="371" /></a></p>
<p>You can have many providers, written in different languages. These providers talk with the Notification Service providing an abstract interface for the Apps. In this way, the end App has just to say &#8220;Write a Mail To X&#8221;, &#8220;Download Todays Mail&#8221;, &#8220;Send an IM to X&#8221;&#8230; and you can intercept notification to displays as a popup on your desktop&#8230; or something similar.</p>
<p><em>This solution will be used in <a title="MokoTouch Project" href="http://th30z.netsons.org/mokotouch">MokoTouch Project</a>, to provide Core Services to the Apps. For more information send me a mail.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2009/08/unified-notification-service-avoid-the-wheel-reinvention/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
