On Mar 2, 2012, at 11:05 AM, Marco Tabini wrote:

> My first instinct is to use a memory-mapped file (e.g.: using NSMutableData) 
> to hold the data while I work on it, but I worry that it will be very slow 
> and that I'm missing a much simpler solution.

I don’t think you can get around the need to swap pixels in and out of memory 
from ‘disk’. In general, mmap is a good way to do that because it’s optimized 
down to the kernel level.

The problem is that if you do this in a naive way, with a single huge pixmap, 
you will have poor locality of reference. Once you get to 1024 RGBA pixels 
across, every scan-line will occupy its own memory page. So any operation that 
crosses lots of scan lines but only uses a small fraction of each one (like 
drawing a vertical line) may involve a lot of paging.

The usual workaround to that is to instead break the image up into rectangular 
tiles, and store each as a separate pixmap. That way most localized graphics 
operations will only involve a fraction of the total number of tiles. (You can 
see Photoshop do this, if you run a slow operation or if it’s had to page part 
of the image out to disk.) I think this will also help with the GPU, because 
CoreGraphics likes to copy pixmaps to GPU memory so they can be rendered and 
manipulated faster.

(That said, I am not a CoreGraphics guru, and I defer to a better answer from 
anyone who is.)

—Jens

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please 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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to