• 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: Object for variable array of fixed structures
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Object for variable array of fixed structures


  • Subject: Re: Object for variable array of fixed structures
  • From: Chris Suter <email@hidden>
  • Date: Tue, 13 Jun 2006 12:54:35 +1000


On 13/06/2006, at 12:28 PM, Steve Sheets wrote:

A number of people have pointed out that I could use NSMutableArray to manage variable size array of NObjects. To use my example, I would store NSRect inside an NSData wrapper, or create subclass of NSObject with an NSRect field or store an NSRect inside an NSValue for each instance of NSRect I want. I would then store X number of these objects using one NSMutableArray.

Yes, this is true, and this is what I am trying to avoid.

Using the NSMutableArray approach, when I want an array with 1000 rectangles, I would be creating 1001 objects, one NSMutableArray & one thousand NSValue objects (using that method). Instead if I use NSMutableData to store allocate enough memory for an array of rectangles, I would only be working with one object, though I will give you that it is an large object.

I not sure what the over head for having a given NSValue object, but I can not imagine that 1001 objects do not take up a bit more of memory than 1 object.

Of course, memory is cheap now a days. I just can't stand storing data that inefficiently.

My structures are strictly scalar values, without reference to handles inside them (a typical example might contain 2 rectangles, a pointer, and some flags, yes, these are for graphic animations).

Any other thoughts on this technique?

Steve Sheets
Midnight Mage Software

NSValue takes up 16 bytes on the heap and I'm not sure if it adds more to store the data.


The downside to using NSMutableData is that it will have the same performance implications as using malloc/realloc if you change the size, i.e. the whole lot might need to be copied when you resize. NSMutableData will probably get round this to some extent by pre- allocating more space than it needs.

If you find performance is an issue, you can always implement your own dynamic array but there's no point doing this unless you need to.


Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Object for variable array of fixed structures (From: Steve Sheets <email@hidden>)
 >Re: Object for variable array of fixed structures (From: Steve Sheets <email@hidden>)

  • Prev by Date: Re: Object for variable array of fixed structures
  • Next by Date: Re: Creating Shared Named Objects
  • Previous by thread: Re: Object for variable array of fixed structures
  • Next by thread: Re: Object for variable array of fixed structures
  • Index(es):
    • Date
    • Thread