Re: nil objects in array
Re: nil objects in array
- Subject: Re: nil objects in array
- From: Oscar Morales Vivó <email@hidden>
- Date: Mon, 2 Jun 2003 13:32:27 +0200
I haven't found that kind of problems myself, but then again I don't
use NSMutableArray on that scale. From what I remember reading on the
list, it doesn't scale that well to that amount of objects.
Depending on what you want to use it for, you might be better off using
C-only types for the array or even the C++ STL (you could just use a
std::map, std::set or something like that to keep stuff ordered).
Hope that helps.
On Saturday, May 31, 2003, at 21:35 Europe/Madrid, Gerriet M. Denkmann
wrote:
A rather strange and puzzling problem:
I have a mutable array and insert objects, keeping the array sorted.
After inserting a few million objects the array contains regions where
all objects are nil (objectAtIndex: return nil).
These regions are often (not always) a small multiple of 1024.
These problems occur soon after the computer starts swapping.
But they are not deterministic - they occur always around a certain
number of objects in the array, but not at the same point exactly.
When I run several of my bug-producing apps concurrently, the error
occurs earlier.
If you suspect some hardware RAM problem: what tools exist to check
the state of the RAM?
Never had any problems impicating RAM before though.
And also: just checked on some other computer: exactly the same
problem. So I really do not believe in bad RAM.
Here is the category for inserting objects (maybe someone discovers a
obvious bug):
And if someone is willing to try the thing I can send you the main
program (which just uses random, creates an object, inserts it - a few
million times).
---------- SortedArray.h --------------
#import <Cocoa/Cocoa.h>
@interface NSMutableArray( SortedArray )
- (id)insert:(id)newElem sortedBy:(SEL)comparator;
@end
---------- SortedArray.m --------------
#import "SortedArray.h"
@implementation NSMutableArray ( SortedArray )
- (id)insert:(id)newElem sortedBy:(SEL)comparator;
{
unsigned int hig = [ self count ] ;
unsigned int lowP = 0 ;
for(;;)
{
if ( hig == lowP ) // insert and stop
{
[ self insertObject: newElem atIndex: hig ] ;
return newElem ;
};
unsigned int mid = lowP / 2 + hig / 2 ; // loP <= mid < hig
id miOb = [ self objectAtIndex: mid ] ;
if ( miOb == nil ) // error
{
NSLog(@"objectAtIndex %u == nil, low %u hig %u count %u", mid,
lowP, hig, [ self count ] );
return nil ;
};
NSComparisonResult res = (NSComparisonResult) [ newElem
performSelector: comparator
withObject: miOb
];
if ( res == NSOrderedAscending ) // lowP ... mid
{
hig = mid ; // new < hig
}
else if ( res == NSOrderedDescending ) // mid + 1 ... hig
{
lowP = mid + 1 ; // lowP <= new
}
else // stop
{
return miOb ;
};
};
}
@end
--------------------- Corner.h ------------------------ (these things
get inserted in the array)
#import <Cocoa/Cocoa.h>
@interface Corner : NSObject
{
unsigned int compactSituation ;
}
- initWithCompact: (unsigned int)ha ;
- (NSComparisonResult)compareWith: (Corner *)oo ;
@end
--------------------- Corner.m ------------------------
#import "Corner.h"
@implementation Corner
- initWithCompact: (unsigned int)ha ;
{
self = [ super init ] ;
compactSituation = ha ;
return self ;
}
- (NSComparisonResult)compareWith: (Corner *)oo ;
{
if ( compactSituation < oo->compactSituation ) return
NSOrderedAscending ;
if ( compactSituation > oo->compactSituation ) return
NSOrderedDescending ;
return NSOrderedSame ;
}
@end
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
/*
Oscar Morales Vivs
Eternal Computer Science Student. Master of C++ Templates. Cocoa Nut.
Computer Graphics Illuminati. UI Guru in Training. Dabbler in all
things CS and most which are not.
Web stuff:
http://homepage.mac.com/oscarmv/index.html
*/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.