I urge you to make sure you understand how mapped memory, virtual memory, and disk caching actually work on your targeted systems (note: the implementations vary across OS X releases). I say this because the majority of Cocoa developers do not understand disk caching and memory mapping on OS X very well because it just doesn't get in the way of most people's work (yes, that is my own assumption). Nevertheless, I am one of the very small percentage who has spent a lot of time fighting it (and even filing bugs); opening and closing literally thousands of media assets is one of those qualifying cases where caching can become a real showstopper or at minimum a performance impediment.
To step around the cache: create a data provider using CGDataProviderCreateSequential
and implement your own reader implementation which opens the file (e.g. using fopen
), then disable the cache using the F_NOCACHE
option of fcntl
before reading. Then you can either run to disk every time you need data or implement your own caching strategy which is optimized for the data you read (e.g. cache the header in memory while the file is being read, but read the image data directly from disk). Life's easier when you ensure the file cannot be altered behind your back. Looks good in theory, anyways.