Skip navigation.
 
mlRe: Implementing fast enumeration
FROM : Jens Alfke
DATE : Sat May 03 03:12:48 2008

On 2 May '08, at 12:18 PM, Ben wrote:

> I have a C array where the elements within it can be converted into 
> multiple objects. Say I have 5 objects. Do I provide them all in one 
> go and return the total number? Or just one per call and return the 
> number remaining?


Return as many as you can at once, for best performance. What makes 
this API fast is that it allows the caller to loop over lots of 
objects at once inline, without having to keep calling into the 
enumerator. In tight loops the overhead of the Obj-C method dispatch 
(or CoreFoundation function call) is the dominating factor.

If you can return large numbers of objects at once, the performance of 
fast-iteration becomes nearly as good as using a native C array. (I 
did some of the early prototyping of this, a few years ago; IIRC, at 
about 50 objects per call, the overhead became negligible.)

—Jens

Related mailsAuthorDate
mlImplementing fast enumeration Ben May 2, 10:41
mlImplementing fast enumeration Ben May 2, 21:18
mlRe: Implementing fast enumeration Jens Alfke May 3, 03:12
mlRe: Implementing fast enumeration Adam R. Maxwell May 3, 03:43
mlRe: Implementing fast enumeration Thomas Backman May 3, 15:10
mlRe: Implementing fast enumeration Ben May 3, 19:08