title: Behavior of NSData initWithBytesNoCopy:length:freeWhenDone:
body: <p>I want to have a fix length mutable content shared data buffer and that is how do I create it:</p>
  
  <pre><code>void *buffer = malloc(length);
  // initialize buffer content
  NSData *sharedData = [[NSData alloc] initWithBytesNoCopy:buffer length:length freeWhenDone:YES]
  </code></pre>
  
  <p>What happen if I modify <code>buffer</code> after I created a NSData from it?  Will NSData reflect the change I did to <code>buffer</code>?</p>
  
  <p>I can guaranty that <code>sharedData</code> will not get dealloc when I want to modify <code>buffer</code>.</p>
  
  <p>This is how I actually want to use it:</p>
  
  <hr>
  
  <pre><code>void *my_alloc(CFIndex allocSize, CFOptionFlags hint, void *info) {return NULL;}
  void my_dealloc(void *ptr, void *info) {
      mach_vm_deallocate(mach_task_self(), (mach_vm_address_t)ptr, (size_t)info);
  }
  </code></pre>
  
  <hr>
  
  <pre><code>size_t length = //some number
  mach_vm_address_t buffer;
  mach_vm_allocate(mach_task_self(), &amp;buffer, length, VM_FLAGS_ANYWHERE);
  // do something to buffer, for example pass to other process using mach RPC and expect other process will modify the content
  CFAllocatorContext context = {0, (void *)length, NULL, NULL, NULL, my_alloc, NULL, my_dealloc, NULL};
  CFAllocatorRef allocator = CFAllocatorCreate(NULL, &amp;context);
  CFDataCreateWithBytesNoCopy(NULL, (const UInt8 *)buffer, length, allocator);
  </code></pre>