On Thu, Mar 20, 2008 at 12:18 AM, Chris Suter <[EMAIL PROTECTED]> wrote:
> I think it's because > > [NSMutableData dataWithBytesNoCopy:returnArray length:length] > > is releasing returnArray and allocating a new buffer for it. I, for one, am surprised that NSMutableData works this way, given that a) the method name specifically requests that no copy is made, and b) there's no particular reason for it to behave that way unless the data is resized. However, the following test code confirms it: #import <Cocoa/Cocoa.h> int main() { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; char *test_string = malloc(8); strncpy(test_string, "testing", 8); NSData *data = [NSData dataWithBytesNoCopy:test_string length:8]; NSMutableData *mutableData = [NSMutableData dataWithBytesNoCopy:test_string length:8]; NSLog(@"%p", test_string); NSLog(@"%p", [data bytes]); NSLog(@"%p", [mutableData bytes]); [pool release]; return 0; } $ gcc -framework Cocoa test_string.m $ ./a.out 2008-03-20 00:42:24.924 a.out[1657:10b] 0x1091d0 2008-03-20 00:42:24.926 a.out[1657:10b] 0x1091d0 2008-03-20 00:42:24.927 a.out[1657:10b] 0x109cb0 $ Hamish _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]