• 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
Re: Is there a way to efficiently access NSArray element contents?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is there a way to efficiently access NSArray element contents?


  • Subject: Re: Is there a way to efficiently access NSArray element contents?
  • From: "Joan Lluch (casa)" <email@hidden>
  • Date: Sun, 8 Jun 2008 20:51:25 +0200


El 08/06/2008, a las 20:13, Brent Fulgham escribió:

I've been enjoying the NSArray/NSMutableArray classes as I work with various user interface features for a program I'm working on that interacts with a legacy C++ library.

I've recently begun considering how to efficiently display the contents of a binary data stream. Currently I'm appending to an NSMutableArray of NSNumber objects, which is great for allowing me to bind to some UI elements in close to real time and has provided a simple and functional mechanism for text numerical display.

Ideally, I'd like to be able to access a raw binary buffer of data so I could for example bind it to something like an OpenGL vector buffer for display. However, unlike an STL vector, I don't think the NS[Mutable]Array provides any guarantees of memory organization, nor any way to 'unbox' the NSNumber to deal with the internal values.

For example, in the STL, I could make use of the fact that the vector template guarantees the storage to be in contiguous memory and accessible as raw double values through the address of the first element of the vector. However, I don't think this is possible via NSMutableArray and NSNumbers.

Is my only option to periodically sync a buffer of binary double values by copying from the NSMutableArray on some periodic basis?

Thanks,

-Brent



Since each item contained in an NSArray is a pointer to an object, you will not be able to retrieve them as raw data of different size even if the pointers in the NSArray were contiguous (which I believe they are)

Did you consider using a NSMutableData object (or even a CFMutableData for efficiency) instead?

You can use an intermediate (fixed length) C vector to receive the stream and transfer it in crunches to a CFMutableData object using the CFDataAppendBytes function. Then you can retrieve contiguous data of any length using the C pointer provided by CFDataBytePtr. However you will still have to transfer it to a NSArray to easily bind it to an user interface element such as a TableView.

I guess you will have to consider if you give priority to the ease of binding to the UI or to the ease of accessing arbitrary length values from the stream.

I would store the data in a CFMutableData object and then transfer it to a NSMutableArray when needed, not the other way round, but of course that depends on what you specifically want to achieve.







_______________________________________________

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: Is there a way to efficiently access NSArray element contents?
      • From: Jean-Daniel Dupas <email@hidden>
References: 
 >Is there a way to efficiently access NSArray element contents? (From: Brent Fulgham <email@hidden>)

  • Prev by Date: Re: Is there a way to efficiently access NSArray element contents?
  • Next by Date: Cocoaheads Lake Forest (93620) meeting Wednesday, 6/18 at 7pm
  • Previous by thread: Re: Is there a way to efficiently access NSArray element contents?
  • Next by thread: Re: Is there a way to efficiently access NSArray element contents?
  • Index(es):
    • Date
    • Thread