title: Memory alignment of arrays
body: <p>I am having trouble aligning memory for DMA transfer on the Cell processor. I need the last 4 bits of an address to be 0.</p>
  
  <p>I have 4 arrays of <code>unsigned int</code> where each element must be <em>aligned</em> in memory so that its (hex) adress ends with a zero.</p>
  
  <p>E.g.</p>
  
  <pre><code>int main()
  {
      size_t i;
  
      static unsigned int a[2] __attribute__ ((aligned (16)));
      static unsigned int b[2] __attribute__ ((aligned (16)));
      static unsigned int c[2] __attribute__ ((aligned (16)));
      static unsigned int d[2] __attribute__ ((aligned (16)));
  
      for (i = 0; i &lt; 2; ++i) {
          printf("a[%u] = %p\n", &amp;a[i]);
          printf("b[%u] = %p\n", &amp;b[i]);
          printf("c[%u] = %p\n", &amp;c[i]);
          printf("d[%u] = %p\n", &amp;d[i]);
      }
  
      return 0;
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>a[0] = 0x10010b60
  b[0] = 0x10010b50
  c[0] = 0x10010b40
  d[0] = 0x10010b30
  a[1] = 0x10010b64
  b[1] = 0x10010b54
  c[1] = 0x10010b44
  d[1] = 0x10010b34
  </code></pre>
  
  <p>The problem here is that the 2nd element of each array doesn't seem to be 16-bit aligned (their address' end with a 4).</p>
  
  <p>I need the addresses to look like this:</p>
  
  <pre><code>a[0] = 0xXXXXXXX0
  b[0] = 0xXXXXXXX0
  c[0] = 0xXXXXXXX0
  d[0] = 0xXXXXXXX0
  a[1] = 0xXXXXXXX0
  b[1] = 0xXXXXXXX0
  c[1] = 0xXXXXXXX0
  d[1] = 0xXXXXXXX0
  </code></pre>