Re: NSEnumerator retaining objects?
Re: NSEnumerator retaining objects?
- Subject: Re: NSEnumerator retaining objects?
- From: "Angela Brett" <email@hidden>
- Date: Wed, 9 Mar 2005 13:11:34 +1300 (NZDT)
- Importance: Normal
Oops, I forgot to copy this to the list... I would be interested in other
people's opinions on this.
> For this application, NSArrays are just a tad overkill (costing a
minimum of 36 bytes per node), where a simple linked list would only
cost 4 bytes per node. And traversing a linked list probably has less
than 1/10th the overhead of either an NSEnumerator or using
objectAtIndex.
>
> On the other hand, I eventually want to sort these nodes someday, and
NSArray has some mighty handy sorting methods. And I've written enough
sorting routines by hand to know that I'm not excited about writing
another one.
>
> Decisions, decisions, ...
Well, you could always write a little method for enumerating the nodes,
which could start out doing an objectAtIndex: but could easily be changed
to using a linked list later (or vice versa.) If you have to be making the
same code in many places that's a good indicator that you need a function
or method to do it.
Mind you, I guess your method would end up being much like an enumerator's
nextObject. Maybe this is the sort of thing that could be done with a
custom NSEnumerator subclass (or at least some object which acts like an
NSEnumerator, I can't remember if there's protocol for it or what)
expecially for enumerating your object's list of whatever they ares? Then
your object would have a 'thingyEnumerator' method (where 'thingy' is
replaced with whatever the array is of) which returns that enumerator, and
you could leave all your code pretty much as is except that instead of
[someInstanceVariable objectEnumerator] you'd call [self
thingyEnumerator]. And to start with, before you've changed it to using a
linked list and written your own enumerator, you could just implement
thingyEnumerator to return [someInstanceVariable objectEnumerator].
_______________________________________________
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