1

I was wondering what is the difference between using a for loop, and using the dispatch_apply function of GCD and couldn't find an answer in the documentation nor in questions here.

Also, will using the GCD function in a runtime situation as a GLKit render/update method will produce better results?

2 Answers2

1

The documentation states :

The dispatch_apply() function provides data-level concurrency through a "for (;;)" loop like primitive:

This means that the code block called by dispatch_apply will not be called sequentially like the for but can execute concurrently.

adig
  • 4,009
  • 1
  • 23
  • 23
1

Also, will using the GCD function in a runtime situation as a GLKit render/update method will produce better results?

The only way to answer that question is to try it and measure the performance.

JeremyP
  • 84,577
  • 15
  • 123
  • 161
  • Well ,just to make it clear - I ran some tests and the GCD is more heavy then the for loop, I suppose that it has a high overhead. –  Apr 27 '12 at 20:19
  • @Mr.Awesome Have you thought about batching up the iterations? i.e. if you have 1,000 iterations to do and four CPUs you could `dispatch_apply` four tasks each going through 250 cases in a for loop. – JeremyP Apr 30 '12 at 08:44