cocoa - Create CGImageRef without caching anything -


i need create thousands of cgimage objects using cgimagesourcecreatethumbnailatindex(...).

the problem when using simple cgdataprovidercreatewithurl(...) followed cgimagesourcecreatethumbnailatindex(...), system caches contents of file (in inactive memory), leads significant performance loss.

the closest solution:

here, suggested use [nsdata datawithcontentsofurl:inurl options:nsuncachedread error:nil] , cgimagesourcecreatewithdata(...) prevent caching files system.

the problem closest solution

this solution requires read entire file memory before creating thumbnail, leads significant performance loss.

things tried:

  1. using [nsdata datawithcontentsofurl:inurl options:nsuncachedread|nsdatareadingmappedalways error:nil]; seems ignore nsuncachedread option (files being cached inactive memory).

  2. using cgdataprovidercreatewithurl, caches files.

  3. edit: using custom cgdataprovider created cgdataprovidercreatesequential(...) @justin suggested, cgimagesourcecreatewithdataprovider calls cgdataprovidercopydata first copy entire image data custom data provider (i want read thumbnail), before call cgimagesourcecreatethumbnailatindex.

any suggestion of how thumbnail without loading entire file memory , without caching it?

p.s. set kcgimagesourceshouldcache kcfbooleanfalse when creating image source , thumbnail, seems relate decoded data, , not raw data cached when reading file.

edit: use 10.8. implementation of functions such cgimagesourcecreatewithdataprovider may different on other platforms/versions.

i urge make sure understand how mapped memory, virtual memory, , disk caching work on targeted systems (note: implementations vary across os x releases). because majority of cocoa developers not understand disk caching , memory mapping on os x because doesn't in way of people's work (yes, own assumption). nevertheless, 1 of small percentage has spent lot of time fighting (and filing bugs); opening , closing literally thousands of media assets 1 of qualifying cases caching can become real showstopper or @ minimum performance impediment.

to step around cache: create data provider using cgdataprovidercreatesequential , implement own reader implementation opens file (e.g. using fopen), disable cache using f_nocache option of fcntl before reading. can either run disk every time need data or implement own caching strategy optimized data read (e.g. cache header in memory while file being read, read image data directly disk). life's easier when ensure file cannot altered behind back. looks in theory, anyways.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -