Is there a way to read data from CGImage without internal caching?









up vote
1
down vote

favorite
1












I am fighting with an internal caching (about 90 MB for 15 mp image ) in CGContextDrawImage/CGDataProviderCopyData functions.

Here is the stack-trace in profiler:



enter image description here



In all cases, IOSurface is created as a "cache", and isn't cleaned after @autoreleasepool is drained.
This leaves a very few chances for an app to survive.

Caching doesn't depend on image size: I tried to render 512x512, as well as 4500x512 and 4500x2500 (full-size) image chunks.



I use @autoreleasepool, CFGetRetainCount returns 1 for all CG-objects before cleaning them.



The code which manipulates the data:



+ (void)render11:(CIImage*)ciImage fromRect:(CGRect)roi toBitmap:(unsigned char*)bitmap 
@autoreleasepool

int w = CGRectGetWidth(roi), h = CGRectGetHeight(roi);

CIContext* ciContext = [CIContext contextWithOptions:nil];
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

CGContextRef cgContext = CGBitmapContextCreate(bitmap, w, h,
8, w*4, colorSpace,
kCGImageAlphaPremultipliedLast




What I know about IOSurface: it's from the previously private framework IOSurface.
CIContext has a function render: ... toIOSurface:.

I've created my IOSurfaceRef and passed it to this function, and the internal implementation still creates its own surface, and doesn't clean it.



So, do you know (or assume):

1. Are there other ways to read CGImage's data buffer except
CGContextDrawImage/CGDataProviderCopyData ?

2. Is there a way to disable caching at render?

3. Why does the caching happen?

4. Can I use some lower-level (while non-private) API to manually clean up system memory?



Any suggestions are welcome.










share|improve this question

























    up vote
    1
    down vote

    favorite
    1












    I am fighting with an internal caching (about 90 MB for 15 mp image ) in CGContextDrawImage/CGDataProviderCopyData functions.

    Here is the stack-trace in profiler:



    enter image description here



    In all cases, IOSurface is created as a "cache", and isn't cleaned after @autoreleasepool is drained.
    This leaves a very few chances for an app to survive.

    Caching doesn't depend on image size: I tried to render 512x512, as well as 4500x512 and 4500x2500 (full-size) image chunks.



    I use @autoreleasepool, CFGetRetainCount returns 1 for all CG-objects before cleaning them.



    The code which manipulates the data:



    + (void)render11:(CIImage*)ciImage fromRect:(CGRect)roi toBitmap:(unsigned char*)bitmap 
    @autoreleasepool

    int w = CGRectGetWidth(roi), h = CGRectGetHeight(roi);

    CIContext* ciContext = [CIContext contextWithOptions:nil];
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

    CGContextRef cgContext = CGBitmapContextCreate(bitmap, w, h,
    8, w*4, colorSpace,
    kCGImageAlphaPremultipliedLast




    What I know about IOSurface: it's from the previously private framework IOSurface.
    CIContext has a function render: ... toIOSurface:.

    I've created my IOSurfaceRef and passed it to this function, and the internal implementation still creates its own surface, and doesn't clean it.



    So, do you know (or assume):

    1. Are there other ways to read CGImage's data buffer except
    CGContextDrawImage/CGDataProviderCopyData ?

    2. Is there a way to disable caching at render?

    3. Why does the caching happen?

    4. Can I use some lower-level (while non-private) API to manually clean up system memory?



    Any suggestions are welcome.










    share|improve this question























      up vote
      1
      down vote

      favorite
      1









      up vote
      1
      down vote

      favorite
      1






      1





      I am fighting with an internal caching (about 90 MB for 15 mp image ) in CGContextDrawImage/CGDataProviderCopyData functions.

      Here is the stack-trace in profiler:



      enter image description here



      In all cases, IOSurface is created as a "cache", and isn't cleaned after @autoreleasepool is drained.
      This leaves a very few chances for an app to survive.

      Caching doesn't depend on image size: I tried to render 512x512, as well as 4500x512 and 4500x2500 (full-size) image chunks.



      I use @autoreleasepool, CFGetRetainCount returns 1 for all CG-objects before cleaning them.



      The code which manipulates the data:



      + (void)render11:(CIImage*)ciImage fromRect:(CGRect)roi toBitmap:(unsigned char*)bitmap 
      @autoreleasepool

      int w = CGRectGetWidth(roi), h = CGRectGetHeight(roi);

      CIContext* ciContext = [CIContext contextWithOptions:nil];
      CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

      CGContextRef cgContext = CGBitmapContextCreate(bitmap, w, h,
      8, w*4, colorSpace,
      kCGImageAlphaPremultipliedLast




      What I know about IOSurface: it's from the previously private framework IOSurface.
      CIContext has a function render: ... toIOSurface:.

      I've created my IOSurfaceRef and passed it to this function, and the internal implementation still creates its own surface, and doesn't clean it.



      So, do you know (or assume):

      1. Are there other ways to read CGImage's data buffer except
      CGContextDrawImage/CGDataProviderCopyData ?

      2. Is there a way to disable caching at render?

      3. Why does the caching happen?

      4. Can I use some lower-level (while non-private) API to manually clean up system memory?



      Any suggestions are welcome.










      share|improve this question













      I am fighting with an internal caching (about 90 MB for 15 mp image ) in CGContextDrawImage/CGDataProviderCopyData functions.

      Here is the stack-trace in profiler:



      enter image description here



      In all cases, IOSurface is created as a "cache", and isn't cleaned after @autoreleasepool is drained.
      This leaves a very few chances for an app to survive.

      Caching doesn't depend on image size: I tried to render 512x512, as well as 4500x512 and 4500x2500 (full-size) image chunks.



      I use @autoreleasepool, CFGetRetainCount returns 1 for all CG-objects before cleaning them.



      The code which manipulates the data:



      + (void)render11:(CIImage*)ciImage fromRect:(CGRect)roi toBitmap:(unsigned char*)bitmap 
      @autoreleasepool

      int w = CGRectGetWidth(roi), h = CGRectGetHeight(roi);

      CIContext* ciContext = [CIContext contextWithOptions:nil];
      CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

      CGContextRef cgContext = CGBitmapContextCreate(bitmap, w, h,
      8, w*4, colorSpace,
      kCGImageAlphaPremultipliedLast




      What I know about IOSurface: it's from the previously private framework IOSurface.
      CIContext has a function render: ... toIOSurface:.

      I've created my IOSurfaceRef and passed it to this function, and the internal implementation still creates its own surface, and doesn't clean it.



      So, do you know (or assume):

      1. Are there other ways to read CGImage's data buffer except
      CGContextDrawImage/CGDataProviderCopyData ?

      2. Is there a way to disable caching at render?

      3. Why does the caching happen?

      4. Can I use some lower-level (while non-private) API to manually clean up system memory?



      Any suggestions are welcome.







      ios caching core-graphics core-image iosurface






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 2 days ago









      Olia_Pavliuk

      517519




      517519






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote













          If you just need to manipulate CIImage data, may consider to use CIImageProcessorKernel to put data into CPU or GPU calculation without extracting them.



          I notice that



          [ciContext
          render:image toBitmap:bitmap rowBytes: w*4 bounds:image.extent format:kCIFormatRGBA8 colorSpace:colorSpace];



          There is no such 90M cache. Maybe it's what you want.



          enter image description here






          share|improve this answer






















          • Thanks! I do need to read the data into unsigned char* buffer. Is it possible with CIImageProcessorKernel ?
            – Olia_Pavliuk
            yesterday










          • It depends on knowledge level. Baseaddress has the data you need. If you cannot get it out, Simply way is to render to somewhere like iosurface or screen then capture screen.
            – E.Coms
            yesterday










          • cgimage can render directly to data. If i call createCGImage, it's 260M. call this it's only 170M during peak.
            – E.Coms
            yesterday










          • "Baseaddress has the data you need" - thanks, I'll try. "cgimage can render directly to data. If i call createCGImage" - yeah, but CGContextDrawImage does that unwanted caching inside
            – Olia_Pavliuk
            yesterday






          • 1




            "Baseaddress has the data you need." Yes, but you may not get it out of the block.
            – E.Coms
            yesterday










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53225002%2fis-there-a-way-to-read-data-from-cgimage-without-internal-caching%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote













          If you just need to manipulate CIImage data, may consider to use CIImageProcessorKernel to put data into CPU or GPU calculation without extracting them.



          I notice that



          [ciContext
          render:image toBitmap:bitmap rowBytes: w*4 bounds:image.extent format:kCIFormatRGBA8 colorSpace:colorSpace];



          There is no such 90M cache. Maybe it's what you want.



          enter image description here






          share|improve this answer






















          • Thanks! I do need to read the data into unsigned char* buffer. Is it possible with CIImageProcessorKernel ?
            – Olia_Pavliuk
            yesterday










          • It depends on knowledge level. Baseaddress has the data you need. If you cannot get it out, Simply way is to render to somewhere like iosurface or screen then capture screen.
            – E.Coms
            yesterday










          • cgimage can render directly to data. If i call createCGImage, it's 260M. call this it's only 170M during peak.
            – E.Coms
            yesterday










          • "Baseaddress has the data you need" - thanks, I'll try. "cgimage can render directly to data. If i call createCGImage" - yeah, but CGContextDrawImage does that unwanted caching inside
            – Olia_Pavliuk
            yesterday






          • 1




            "Baseaddress has the data you need." Yes, but you may not get it out of the block.
            – E.Coms
            yesterday














          up vote
          1
          down vote













          If you just need to manipulate CIImage data, may consider to use CIImageProcessorKernel to put data into CPU or GPU calculation without extracting them.



          I notice that



          [ciContext
          render:image toBitmap:bitmap rowBytes: w*4 bounds:image.extent format:kCIFormatRGBA8 colorSpace:colorSpace];



          There is no such 90M cache. Maybe it's what you want.



          enter image description here






          share|improve this answer






















          • Thanks! I do need to read the data into unsigned char* buffer. Is it possible with CIImageProcessorKernel ?
            – Olia_Pavliuk
            yesterday










          • It depends on knowledge level. Baseaddress has the data you need. If you cannot get it out, Simply way is to render to somewhere like iosurface or screen then capture screen.
            – E.Coms
            yesterday










          • cgimage can render directly to data. If i call createCGImage, it's 260M. call this it's only 170M during peak.
            – E.Coms
            yesterday










          • "Baseaddress has the data you need" - thanks, I'll try. "cgimage can render directly to data. If i call createCGImage" - yeah, but CGContextDrawImage does that unwanted caching inside
            – Olia_Pavliuk
            yesterday






          • 1




            "Baseaddress has the data you need." Yes, but you may not get it out of the block.
            – E.Coms
            yesterday












          up vote
          1
          down vote










          up vote
          1
          down vote









          If you just need to manipulate CIImage data, may consider to use CIImageProcessorKernel to put data into CPU or GPU calculation without extracting them.



          I notice that



          [ciContext
          render:image toBitmap:bitmap rowBytes: w*4 bounds:image.extent format:kCIFormatRGBA8 colorSpace:colorSpace];



          There is no such 90M cache. Maybe it's what you want.



          enter image description here






          share|improve this answer














          If you just need to manipulate CIImage data, may consider to use CIImageProcessorKernel to put data into CPU or GPU calculation without extracting them.



          I notice that



          [ciContext
          render:image toBitmap:bitmap rowBytes: w*4 bounds:image.extent format:kCIFormatRGBA8 colorSpace:colorSpace];



          There is no such 90M cache. Maybe it's what you want.



          enter image description here







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited yesterday

























          answered 2 days ago









          E.Coms

          1,1161410




          1,1161410











          • Thanks! I do need to read the data into unsigned char* buffer. Is it possible with CIImageProcessorKernel ?
            – Olia_Pavliuk
            yesterday










          • It depends on knowledge level. Baseaddress has the data you need. If you cannot get it out, Simply way is to render to somewhere like iosurface or screen then capture screen.
            – E.Coms
            yesterday










          • cgimage can render directly to data. If i call createCGImage, it's 260M. call this it's only 170M during peak.
            – E.Coms
            yesterday










          • "Baseaddress has the data you need" - thanks, I'll try. "cgimage can render directly to data. If i call createCGImage" - yeah, but CGContextDrawImage does that unwanted caching inside
            – Olia_Pavliuk
            yesterday






          • 1




            "Baseaddress has the data you need." Yes, but you may not get it out of the block.
            – E.Coms
            yesterday
















          • Thanks! I do need to read the data into unsigned char* buffer. Is it possible with CIImageProcessorKernel ?
            – Olia_Pavliuk
            yesterday










          • It depends on knowledge level. Baseaddress has the data you need. If you cannot get it out, Simply way is to render to somewhere like iosurface or screen then capture screen.
            – E.Coms
            yesterday










          • cgimage can render directly to data. If i call createCGImage, it's 260M. call this it's only 170M during peak.
            – E.Coms
            yesterday










          • "Baseaddress has the data you need" - thanks, I'll try. "cgimage can render directly to data. If i call createCGImage" - yeah, but CGContextDrawImage does that unwanted caching inside
            – Olia_Pavliuk
            yesterday






          • 1




            "Baseaddress has the data you need." Yes, but you may not get it out of the block.
            – E.Coms
            yesterday















          Thanks! I do need to read the data into unsigned char* buffer. Is it possible with CIImageProcessorKernel ?
          – Olia_Pavliuk
          yesterday




          Thanks! I do need to read the data into unsigned char* buffer. Is it possible with CIImageProcessorKernel ?
          – Olia_Pavliuk
          yesterday












          It depends on knowledge level. Baseaddress has the data you need. If you cannot get it out, Simply way is to render to somewhere like iosurface or screen then capture screen.
          – E.Coms
          yesterday




          It depends on knowledge level. Baseaddress has the data you need. If you cannot get it out, Simply way is to render to somewhere like iosurface or screen then capture screen.
          – E.Coms
          yesterday












          cgimage can render directly to data. If i call createCGImage, it's 260M. call this it's only 170M during peak.
          – E.Coms
          yesterday




          cgimage can render directly to data. If i call createCGImage, it's 260M. call this it's only 170M during peak.
          – E.Coms
          yesterday












          "Baseaddress has the data you need" - thanks, I'll try. "cgimage can render directly to data. If i call createCGImage" - yeah, but CGContextDrawImage does that unwanted caching inside
          – Olia_Pavliuk
          yesterday




          "Baseaddress has the data you need" - thanks, I'll try. "cgimage can render directly to data. If i call createCGImage" - yeah, but CGContextDrawImage does that unwanted caching inside
          – Olia_Pavliuk
          yesterday




          1




          1




          "Baseaddress has the data you need." Yes, but you may not get it out of the block.
          – E.Coms
          yesterday




          "Baseaddress has the data you need." Yes, but you may not get it out of the block.
          – E.Coms
          yesterday

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53225002%2fis-there-a-way-to-read-data-from-cgimage-without-internal-caching%23new-answer', 'question_page');

          );

          Post as a guest














































































          Popular posts from this blog

          Use pre created SQLite database for Android project in kotlin

          Darth Vader #20

          Ondo