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: Daniel Jalkut <email@hidden>
- Date: Wed, 02 Nov 2005 10:14:06 -0500
Andrei - it's definitely a bad idea to init an object over and over.
You should be allocating a new NSData object here every time you need
one. An appropriate convenience method can be found in the
"dataWithBytes:"family of class methods on NSData. E.g.:
return [NSData dataWithBytes:bigIoBuffer length:bytesRead];
Daniel
On Nov 2, 2005, at 9:57 AM, Andrei Tchijov wrote:
What I am trying to achieve is to have NSData object which wraps
IO buffer. For example:
...
int bigIoBufferSize = xxx;
char* bigIoBuffer = (char*) malloc( bigIoBufferSize );
NSData* ioData = [ NSData alloc ];
...
- (NSData*) readData {
...
read data into bigIoBuffer
save number of bytes read in bytesRead
...
return [ ioData initWithBytesNoCopy: bigIoBuffer length:
bytesRead ];
}
...
- (void) copyData {
NSData* dataIn = [ self readData ];
[ self writeData: dataIn ];
}
...
So questions are:
1) Is it legal to do initWithBytesNoCopy:length: more then once on
the same object?
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?
You comments are greatly appreciated,
Andrei Tchijov
Leaping Bytes, LLC
web: www.leapingbytes.com
email: email@hidden
AIM: leapingbytes
Google: email@hidden
ICQ: 151229319
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
sweater.com
This email sent to email@hidden
_______________________________________________
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