Re: NSMutableData doesn't support dataWithBytesNoCopy properly
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.