Thursday, January 2, 2014

With a multi-threaded several times slower

Depressed.
Open more than one thread in viewDidLoad where to process the data.
Many data, however, if not multi-threaded, the time it takes about 1 second. Tragedy after using a multi-threaded, time spent probably 10 - 15 seconds.
Multi-threaded code is as follows:
[NSThread detachNewThreadSelector: @ selector (initData) toTarget: self withObject: nil];
Find good help, why is this result? Did not dare to mind
Reply:
Single-step the next, probably found the scope of the problem.
There is a cycle-threaded task, the problem is in this cycle, multi-threaded extra time spent on this cycle.
Reply:
Problems have been solved, forgot to use NSAutoreleasePool.

Reply:
Actually a man in a monologue.
I was a cloud.
Reply:
Will lz, plus NSAutoreleasePool, how efficient?
Reply:
Then the multi-threaded, it is recommended to use NSInvocationOperation
Reply:
reference to the third floor kongfo1019 reply:
actually a person in the monologue.
I was a cloud.

Ashamed, the problem I encountered was not releasing memory, so multi-thread operation due to lack of enough space to hang. A little slower than the single-threaded speed, in addition to synchronization, no feeling.

Reply:
references, 5th Floor zhanglei5415 reply:
then a multi-threaded, it is recommended to use NSInvocationOperation


Easy access for a moment, seemingly NSinvocationOperation is to maintain a task queue, which itself is performed automatically each queue member? I do not know what is the difference and NSThread?

No comments:

Post a Comment