Question on NSOutputStream -write:maxLength:
Question on NSOutputStream -write:maxLength:
- Subject: Question on NSOutputStream -write:maxLength:
- From: Carl Hoefs <email@hidden>
- Date: Wed, 02 Jul 2014 11:15:12 -0700
I'm going through the Apple NSOutputStream online documentation. Below is "Listing 2: Handling a space-available event" (from https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Streams/Articles/WritingOutputStreams.html)
- (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode
{
switch(eventCode) {
case NSStreamEventHasSpaceAvailable: {
uint8_t *readBytes = (uint8_t *)[_data mutableBytes];
readBytes += byteIndex; // instance variable to move pointer
int data_len = [_data length];
unsigned int len =
(data_len-byteIndex >= 1024) ? 1024 : (data_len-byteIndex);
--> uint8_t buf[len];
--> (void)memcpy(buf, readBytes, len);
--> len = [stream write:(const uint8_t *)buf maxLength:len];
byteIndex += len;
break;
}
// continued ...
}
}
What's the purpose of the memcpy? Couldn't the data bytes in the NSData object be accessed via pointer, like this:
len = [stream write:(const uint8_t *)readBytes maxLength:len];
I'm worried that I'm overlooking something important.
-Carl
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden