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 protected])

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to