• 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
Partially release NSMutableData
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Partially release NSMutableData


  • Subject: Partially release NSMutableData
  • From: Marcus Karlsson <email@hidden>
  • Date: Wed, 04 Aug 2010 15:02:26 +0200

Hello.

The subject of this thread is probably somewhat weird at first but let me explain.

Let's say that I'm receiving data from the network and need to store it in a buffer. I need to store it until enough data has been collected, where what is considered "enough" is impossible to know beforehand. It is only possible to know by examining the data as it is received.

Right now I'm using NSMutableData. It's a quite nifty class where I can easily append data in the end as it arrives.

Once enough data has arrived it is used by the program and is then no longer needed. What I want to know is what would be the best practice in order to save memory by removing just the data that is no longer needed. So far I have three alternatives.

1. Instead of a single NSMutableData object store each chunk using NSMutableArray and remove them one by one as they are no longer needed.

2. Use a single NSMutableData object. Once enough data has arrived copy the data that may have been appended later to a new NSMutableData object and release the first object.

3. Use a single NSMutableData object. Once enough data has arrived move the data that may have been appended later to the beginning and adjust the capacity.

Any opinions on which one to use or ideas on even better ones?

Marcus

_______________________________________________

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


  • Follow-Ups:
    • Re: Partially release NSMutableData
      • From: "A.M." <email@hidden>
    • Re: Partially release NSMutableData
      • From: Graham Cox <email@hidden>
  • Prev by Date: Re: [Q] Enter Key & HIG
  • Next by Date: Problem with animator-proxy in 10.5 and NSApps -runModalForWindow
  • Previous by thread: Re: Getting a list of web browsers
  • Next by thread: Re: Partially release NSMutableData
  • Index(es):
    • Date
    • Thread