Jim
Jim

Reputation: 4719

iPhone: Best Practice for Using NSThread to Load Thousands of Images?

I am trying to load thousands of images using NSThread but the performance is quite slow.

What would be the best practice to use NSThread to download thousands of images?

Thanks,
Jim.

Upvotes: 0

Views: 1100

Answers (3)

Stefan Arentz
Stefan Arentz

Reputation: 34935

Also consider to use the NSOperationQueue to coordinate those downloads. Using the NSOperationQueue and NSOperation classes you can schedule a thousand downloads but make sure that only a certain amount of downloads happen concurrently.

To score bonus points, use the Reachability API to see if the user is on 3G or Wifi and set the number of concurrent downloads based on that.

Upvotes: 3

TechZen
TechZen

Reputation: 64428

NSThread isn't the problem. It sounds like you might be simply overwhelming the iPhone hardware. Remember, a mobile platform has only a fraction of power of even the slowest laptop.

Look at how the photo app has to blur-fade in images at times. Sometimes, it has to do that with thumbnails as well. It can take up to 10-20 seconds to display a graphics intensive web page.

It sounds like you need to rethink your design. Unless you're loading microscopically small images, your simply not going to load "thousands" of them in a timely manner on iPhone hardware. You need to load as you display. Logically chop the images up into groups and then have the user navigate to the group they want and then load only that small group.

Upvotes: 3

epatel
epatel

Reputation: 46051

If you are downloading images over http I recommend using the ASIHTTPRequest framwork. It can easily download html, images and other stuff asynchronous.

But, be careful not to download to many things at the same time. I have read somewhere that 10 http connections at the same time should be a good amount. (Somewhere was the AppSales-Mobile project ReviewUpdater.h value set by jonkean in his commit)

Upvotes: 1

Related Questions