• 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
Need advice about [NSInputStream read:maxLength:] performance.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Need advice about [NSInputStream read:maxLength:] performance.


  • Subject: Need advice about [NSInputStream read:maxLength:] performance.
  • From: Motti Shneor <email@hidden>
  • Date: Thu, 10 Sep 2015 00:07:31 +0300

Hi everyone. 

I’m re-implementing an old media-streaming socket using NSStream APIs (along with some CFNetwork and posix APIs for configuring the underlying sockets).

I’m creating my stream-pair simply like thus

::CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, (__bridge CFStringRef)hostAddress, portNum, &readStream, &writeStream);

Later, when handling the NSStreamEventHasBytesAvailable event in my  - (void)stream:handleEvent:  

I’m reading the data awaiting using the normal 

NSInteger readLength = [_inputStream read:buffer maxLength:maxReadLength];

My question: is there a special penalty or cost for calling the read:maxLength: frequently? 

I need reading messages off the stream, each prefixed by 4 bytes containing its size. I was wondering if it was advisable to first read just the size (4 bytes) then read the rest of the message, or maybe it was better to have a big buffer into which to “drain” the stream, then parse my messages off the buffer? 

The first approach is simpler to implement and avoids further data copying, while the second approach reduces the frequency of calling read:maxLength:but will force me to copy messages off my internal buffer.

My messages are video/audio and similar. Audio messages are 25 times a second, video messages are roughly 32 a second.

Can anyone hint me about the better approach? 

Thanks

Motti Shneor

 _______________________________________________
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

  • Follow-Ups:
    • Re: Need advice about [NSInputStream read:maxLength:] performance.
      • From: Jens Alfke <email@hidden>
    • Re: Need advice about [NSInputStream read:maxLength:] performance.
      • From: "Quinn \"The Eskimo!\"" <email@hidden>
  • Prev by Date: Re: protected ports & sandboxing
  • Next by Date: Re: Need advice about [NSInputStream read:maxLength:] performance.
  • Previous by thread: Re: protected ports & sandboxing
  • Next by thread: Re: Need advice about [NSInputStream read:maxLength:] performance.
  • Index(es):
    • Date
    • Thread