• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSMutableData doesn't support dataWithBytesNoCopy properly
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSMutableData doesn't support dataWithBytesNoCopy properly


  • Subject: Re: NSMutableData doesn't support dataWithBytesNoCopy properly
  • From: Marcel Weiher <email@hidden>
  • Date: Sun, 17 Feb 2002 00:33:56 +0100

On Saturday, February 16, 2002, at 08:37 PM, Simson Garfinkel wrote:

[..]

data = [NSMutableData dataWithBytesNoCopy:"12345" length:5];

NSLog(@"data=%@",data);
[pool release];
return 0;
}

Here are the results:

[simsong@localhost ~] 362 % ./x
*** malloc[2580]: Deallocation of a pointer not malloced: 0x1ee0; This could be a double free(), or free() called with the middle of an allocated block; Try setting environment variable MallocHelp to see tools to help debug
2002-02-16 14:30:10.191 x[2580] data=<31323334 35>
[simsong@localhost ~] 363 % %%


[..]
I would like NSMutableData to support dataWithBytesNoCopy properly, but I also want it to handle append properly. Has anybody else other encountered this?

Yes, NSData (a) assumes malloced() memory and (b) takes ownership of that memory. I just checked, and this doesn't seem to be documented in the current docs. Hmm, I wonder where this was made known.

Anyway, there is some undocumented NSData API that will allow you to specify wether the memory will be freed or not. There is also CFData:

CF_EXPORT
CFDataRef CFDataCreateWithBytesNoCopy(CFAllocatorRef allocator, const UInt8 *bytes, CFIndex length, CFAllocatorRef bytesDeallocator);
/* Pass kCFAllocatorNull as bytesDeallocator to assure the bytes aren't freed */

Marcel



--
Marcel Weiher Metaobject Software Technologies
email@hidden www.metaobject.com
Metaprogramming for the Graphic Arts. HOM, IDEAs, MetaAd etc.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: NSMutableData doesn't support dataWithBytesNoCopy properly
      • From: Lance Bland <email@hidden>
References: 
 >NSMutableData doesn't support dataWithBytesNoCopy properly (From: Simson Garfinkel <email@hidden>)

  • Prev by Date: Re: NSMutableData doesn't support dataWithBytesNoCopy properly
  • Next by Date: Re: NSMutableData doesn't support dataWithBytesNoCopy properly
  • Previous by thread: Re: NSMutableData doesn't support dataWithBytesNoCopy properly
  • Next by thread: Re: NSMutableData doesn't support dataWithBytesNoCopy properly
  • Index(es):
    • Date
    • Thread