NSKeyedArchiver collapsing under weight
NSKeyedArchiver collapsing under weight
- Subject: NSKeyedArchiver collapsing under weight
- From: Brent Gulanowski <email@hidden>
- Date: Tue, 24 Jun 2003 11:20:14 -0400
Hi,
I've hit a bad performance quandary. I have some data which can vary in
content, so I am using dictionaries to store it. These are representing
lines in a table, which is being parsed as part of the generation of a
new document in the program.
Generating the dictionaries is no problem. 14,000 can be created in
around half a second. However, trying to archive them is another story.
I'm guessing that, even though there is no conditional encoding, the
overhead of checking each new object against the table of previously
generated tokens is simply not scaling. Each dictionary contains
(currently) eight entries: all NSNumbers, but could in future contain
as many as 250 such values.
Using non-keyed archiving seems to be no trouble. If keyed archiving is
meant to be scalable, what errors could I have made which would have
caused issues? Here is some code:
//--------------
- (NSData *)dataRepresentationOfType:(NSString *)type {
#if USE_KEYED_ARCHIVING
// create keyed archiver and add each instance object
NSMutableData *data = [NSMutableData data];
NSArchiver *archiver = [[NSKeyedArchiver alloc]
initWithDataForWriting:data];
[archiver encodeObject:FITSFileName forKey:FITS_FILE_NAME_KEY];
[archiver encodeObject:allSources forKey:SOURCES_ARRAY_KEY];
[archiver finishEncoding];
[archiver release];
return data;
#else
NSDictionary *rootDictionary = [[NSMutableDictionary alloc]
initWithObjectsAndKeys:
FITSFileName,
FITS_FILE_NAME_KEY,
allSources,
SOURCES_ARRAY_KEY,
nil];
return [NSArchiver archivedDataWithRootObject:rootDictionary];
#endif
}
- (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)type {
if( [type isEqualToString:SCATALOGUE_DOCUMENT] ) {
#if USE_KEYED_ARCHIVING
// read each top level object graph from the data using keyed
unarchiver
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc]
initForReadingWith
Data:data];
FITSFileName = [[unarchiver decodeObjectForKey:FITS_FILE_NAME_KEY]
retain];
allSources = [[unarchiver decodeObjectForKey:SOURCES_ARRAY_KEY]
retain];
#else
NSDictionary *rootDictionary = [NSUnarchiver
unarchiveObjectWith
Data:data];
FITSFileName = [[rootDictionary objectForKey:FITS_FILE_NAME_KEY]
retain];
allSources = [[rootDictionary objectForKey:SOURCES_ARRAY_KEY]
retain];
#endif
[self sources];
return YES;
}
else
return NO;
}
//--------------
Brent
No one really knows enough to be a pessimist. -- William Blake
_______________________________________________
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.