Re: Is it a bad idea to invoke "init..." over and over on the same object?
Re: Is it a bad idea to invoke "init..." over and over on the same object?
- Subject: Re: Is it a bad idea to invoke "init..." over and over on the same object?
- From: Jack Nutting <email@hidden>
- Date: Wed, 2 Nov 2005 16:15:14 +0100
On 11/2/05, Andrei Tchijov <email@hidden> wrote:
>
> 1) Is it legal to do initWithBytesNoCopy:length: more then once on
> the same object?
Definitely not! Calling an init method more than once on any object is a
no-no.
2) If it is, will NSData just forget about "current" bytes and
> change internal pointers to point to new one or will it try to free it?
In the best case, the NSData instance will leak all over the place. In the
worst case, it could conceivably cause a crash.
IMHO you are much better off modifying your readData method like this:
- (NSData*) readData {
...
read data into bigIoBuffer
save number of bytes read in bytesRead
...
return [NSData dataWithBytesNoCopy: bigIoBuffer length: bytesRead ];
}
What that will do is return a new, autoreleased NSData instance.
--
// jack
// http://www.nuthole.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden