• 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: NSRectArray by reference
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSRectArray by reference


  • Subject: Re: NSRectArray by reference
  • From: Uli Kusterer <email@hidden>
  • Date: Mon, 10 Sep 2007 16:02:27 +0200

On 10.09.2007, at 12:59, Alastair Houghton wrote:
On 9 Sep 2007, at 22:28, Uli Kusterer wrote:
D) Create your own KDRectArray class that internally uses calloc()/ free() to create/dispose of its memory block, but wraps it all nicely in an Objective C object that everyone can use, including indexed accessors like:

IMHO if you're doing that, it's worth considering using an NSMutableData as the backing store (inside your KDRectArray object), because that strategy will work better with garbage collected code. (The existence of GC is something that's been public for some time, so I don't think I'm revealing anything "secret" by saying that; I'm not sure I can explain *why* using NSMutableData might be better though :-).)

I'm not garbage-collected yet, so my stance on this is: Let's burn that bridge when we get to it ;-)


The disadvantage of using NSData as a replacement for malloc in cases like these is that you always need to do ((NSRect*)[myData mutableBytes]) when you want to access the array, instead of just going through an NSRect* right away. Of course, you could add a second ivar, but really, that would be kind of wasteful.

I'm not quite sure why it would be a problem to use malloc, though. After all, most Apple classes will eventually be doing that internally, garbage collected or not, so this problem has to have been solved already, if it even is one. Of course, in garbage collected systems you're never supposed to rely on memory actually going away when you think, but as long as the internal storage gets freed when the object is reclaimed, who cares whether that's now or five minutes from now during the next GC cycle.

Cheers,
-- M. Uli Kusterer
http://www.zathras.de



_______________________________________________

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


References: 
 >NSRectArray by reference (From: Keith Duncan <email@hidden>)
 >Re: NSRectArray by reference (From: Brian Stern <email@hidden>)
 >Re: NSRectArray by reference (From: Uli Kusterer <email@hidden>)
 >Re: NSRectArray by reference (From: Alastair Houghton <email@hidden>)

  • Prev by Date: Re: Cocoa with CodeWarrior?
  • Next by Date: Re: characters in cocoa
  • Previous by thread: Re: NSRectArray by reference
  • Next by thread: determine volume name for folder that does not exist
  • Index(es):
    • Date
    • Thread