Re: NSRectArray by reference
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