Re: NSMutableArray + NSEnumerator = No Memory
Re: NSMutableArray + NSEnumerator = No Memory
- Subject: Re: NSMutableArray + NSEnumerator = No Memory
- From: Alastair Houghton <email@hidden>
- Date: Mon, 24 Sep 2007 15:58:14 +0100
On 23 Sep 2007, at 19:39, James Bucanek wrote:
Chris Suter <mailto:email@hidden> wrote (Sunday,
September 23, 2007 4:18 PM +1000):
There is a fourth option which is that you implement your own
enumerator. Something like this would do:
<code snipped>
That's an excellent solution, Chris. It has the advantage that it's
a drop-in replacement for NSEnumerator in my code. It has the
disadvantage that it's just a layer of abstraction over
objectAtIndex:, so it would be slower than the built-in
NSEnumerator. But it's worth profiling to see just home much slower.
If the code Chris gave is too slow, you could:
1. Change it to get an IMP for -objectAtIndex:, then re-test.
2. Change it to use CFArrayGetValueAtIndex(), then re-test.
One or other of these should make it (a little bit) faster.
(Oh, also, the -init method Chris wrote is slightly wrong... it
*should* read:
- (MemoryEfficientEnumerator *)initWithArray:(NSArray *)anArray
{
if ((self = [super init])) {
numObjects = [anArray count];
array = [anArray retain];
}
return self;
}
but you probably spotted that already :-) A hazard of typing code in
Mail.app, I'm sure [perhaps there should be a mail plug-in for
compiling simple test programs to make sure they work :-D])
Kind regards,
Alastair.
--
http://alastairs-place.net
_______________________________________________
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