• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Question on NSOutputStream -write:maxLength:
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Prev by Date: Re: TCP sockets with Bonjour-discovered address
  • Next by Date: Re: TCP sockets with Bonjour-discovered address
  • Previous by thread: Re: TCP sockets with Bonjour-discovered address
  • Next by thread: Is there a transactional data limit with NSStreams?
  • Index(es):
    • Date
    • Thread