title: Fastest way to check mass data if null in C?
body: <p>I have a mass of data, maybe 4MB. Now want to check if all bits in it are 0.</p>
  
  <p>Eg: 
  Here is the data:</p>
  
  <pre><code>void* data = malloc(4*1024*1024);
  memset(data, 0, 4*1024*1024);
  </code></pre>
  
  <p>Check if all bits in it are 0. Here is my solution which is not fast enough:</p>
  
  <pre><code>int dataisnull(char* data, int length)
  {
      int i = 0;
      while(i&lt;length){
          if (data[i]) return 0;
          i++;
      }
      return 1;
  }
  </code></pre>
  
  <p>This code might have some things to improve in performance. For example, in 32/64 bits machine, checking 4/8 bytes at a time may be faster.</p>
  
  <p>So I wonder what is the fastest way to do it?</p>