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 12:26:59 -0700
(mistakenly 1st posted to cocoa-dev)
I'm going through the Apple NSOutputStream online documentation. Below is "Listing 2: Handling a space-available event" (fromhttps://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
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden