title: How does this code find the memory aligned size of a Struct in swift? Why does it need binary operations?
body: <p>I am going through the Metal iOS Swift example trying to understand the triple buffering practice they suggest. This is shown inside of the demo for the uniform animations.</p>
  
  <p>As I understand it aligned memory simply starts at a specefic increment that is a multiple of some byte amount that the device really likes. My confusion is this line of code</p>
  
  <pre><code>// The 256 byte aligned size of our uniform structure
  let alignedUniformsSize = (MemoryLayout&lt;Uniforms&gt;.size &amp; ~0xFF) + 0x100
  </code></pre>
  
  <p>they use it to find the size and byte of the Uniforms struct. I am confused about why there are binary operations here I am really not sure what they do.</p>
  
  <p>If it helps this aligned size is used to create a buffer like this. I am fairly sure that buffer allocates byte aligned memory automatically and is henceforth used as the memory storage location for the uniforms.</p>
  
  <pre><code>let buffer = self.device.makeBuffer(length:alignedUniformsSize * 3, options:[MTLResourceOptions.storageModeShared])
  </code></pre>
  
  <p>So essentially rather than going through the trouble of allocating byte aligned memory by yourself they let metal do it for them.</p>
  
  <p>Is there any reason that the strategy they used when they did <code>let allignedUniformsSize =</code> would not work for other types such as <code>Int</code> or <code>Float</code> etc?</p>