[solved] Re: Coredata performance problem : massive insertion produces error in allocate region
[solved] Re: Coredata performance problem : massive insertion produces error in allocate region
- Subject: [solved] Re: Coredata performance problem : massive insertion produces error in allocate region
- From: "Kubernan At 10191 Tec." <email@hidden>
- Date: Sun, 11 Mar 2007 16:23:29 +0100
Of course !!! NSAutoreleasePool.. forgot it ! It works better now :-)
"small time" means less than 30 seconds. If i cumulate the instances
of the entity in a array and realize an add of this array at the end
of the 60 000 calls, the process is very fast (i.e < 30 seconds).
Otherwise (adding instances for each of the 60 000 calls) this can
take several minutes.
Thx for your help.
K.
Le 11 mars 07 à 13:45, Julio Cesar Silva dos Santos a écrit :
Put all your code inside an NSAutoreleasePool:
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
.
.
.
[pool release];
and delete the line [obj release]. But 'insert a large amount of
instances in small time' may be difficult to figure out if we don't
know what you mean by small time. You can take a look at NSThread.
It will prevent UI locking.
Julio Cesar Silva dos Santos
email@hidden
Skype: jcssantos01
Blogjective-C
http://www.jcs.santos.nom.br/wp
FetchYourLyrics
http://www.jcs.santos.nom.br/fyl/fyl.html
On 11/03/2007, at 06:46, Kubernan At 10191 Tec. wrote:
Hello,
I'm new in coredata and i have a big performance problem.
My application inserts in one step about 60 000 instances of an
entity (calling 60 000 times this method):
-(void)insertALine:(NSString *)line
{
countOfInsertedLines++;
NSArray *anArray = [line componentsSeparatedByString:@" "];
NSEntityDescription *entity;
entity = [[[[NSApp delegate] managedObjectModel] entitiesByName]
objectForKey: @"Entity"];
NSManagedObject *obj;
obj = [[NSClassFromString([entity managedObjectClassName]) alloc]
initWithEntity:entity insertIntoManagedObjectContext:[[NSApp
delegate] managedObjectContext]];
[obj setValue:[anArray objectAtIndex:0] forKey:@"val1"];
[obj setValue:[NSNumber numberWithInt:[[anArray objectAtIndex:1]
intValue]] forKey:@"val2"];
[obj setValue:[NSNumber numberWithInt:[[anArray objectAtIndex:2]
intValue]] forKey:@"val3"];
[obj setValue:selectedObject forKey:@"relationship"]; //
selectedObject<-->>Entity relationship
if (countOfInsertedLines > SYNC_CONTEXT_AFTER_MAX_LINE_INSERTED)
{
countOfInsertedLines = 0;
NSError *error;
[[[NSApp delegate] managedObjectContext] save:&error];
}
[obj release];
}
After several minutes, this code produces this error :
malloc: *** vm_allocate(size=81920) failed (error code=3)
malloc: *** error: can't allocate region
malloc: *** set a breakpoint in szone_error to debug
What i'm doing wrong ? What is the best strategy if i want to
insert large amount of instances in small time ? (the persistent
store coordinator uses NSSQLiteStoreType)
Thanks for your help.
K.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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