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 (Cocoa-dev@lists.apple.com)

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

This email sent to arch...@mail-archive.com

Reply via email to