nil objects in array
nil objects in array
- Subject: nil objects in array
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Sat, 31 May 2003 21:35:11 +0200
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.
- Prev by Date:
Pipe
- Previous by thread:
Pipe
- Index(es):