title: How to initialize an NSData in order to store MAX_SIZE_BUFFER bytes?
body: <p>I have just realized I lost 30 minutes searching in Xcode NSData Class reference how to do this in objc (sorry I explain this in C as this in the only language which comes without thinking too much):</p>
  
  <pre><code>#define MAX_SIZE_BUFFER 500
  byte *ptr;
  ptr = malloc(MAX_SIZE_BUFFER * sizeof(byte));
  memset(ptr, 0, MAX_SIZE_BUFFER);
  </code></pre>
  
  <p>I started to code like this but never found out how to init MAX_SIZE_BUFFER and set all bytes to 0 in a smart way:</p>
  
  <pre><code>#define MAX_SIZE_BUFFER 500
  NSData *ptr
  ptr = [[[NSData] alloc] init]; // impossible to specify MAX_SIZE_BUFFER in the allocation.
  </code></pre>
  
  <p>Thus I told myself, let's use a class method like: </p>
  
  <pre><code>+ data
  + dataWithBytes:length:
  + dataWithBytesNoCopy:length:
  + dataWithBytesNoCopy:length:freeWhenDone:
  + dataWithContentsOfFile:
  + dataWithContentsOfFile:options:error:
  + dataWithContentsOfMappedFile:
  + dataWithContentsOfURL:
  + dataWithContentsOfURL:options:error:
  + dataWithData:
  </code></pre>
  
  <p>but none of them enables to do the alloc and blank init symply.</p>
  
  <p>For example: + dataWithBytes:length: requires that an alternate C buffer be created and given as a parameter to the method.</p>
  
  <p>Should I consider myself like an idiot or like an objc bad programmer ?</p>
  
  <p>Seriously, do you have a smart and simple method ?</p>
  
  <p>Apple92</p>