代码之家  ›  专栏  ›  技术社区  ›  olha

有没有一种方法可以在没有内部缓存的情况下从CGImage读取数据?

  •  3
  • olha  · 技术社区  · 6 年前

    我正在与一个内部缓存(约90 MB的15MP图像)的战斗中 CGContextDrawImage / CGDataProviderCopyData 功能。
    以下是探查器中的堆栈跟踪:

    enter image description here

    在所有情况下, IOSurface 创建为“缓存”,并且在 @autoreleasepool
    这给应用程序留下了很少的生存机会。
    512x512 以及 4500x512 4500x2500 (全尺寸)图像块。

    @自动释放池 , CFGetRetainCount 返回 1 CG

    操作数据的代码:

    + (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 | kCGBitmapByteOrder32Big);
    
    
            CGImageRef cgImage = [ciContext createCGImage:ciImage
                                             fromRect:roi
                                               format:kCIFormatRGBA8
                                           colorSpace:colorSpace
                                             deferred:YES];
    
    
            CGContextDrawImage(cgContext, CGRectMake(0, 0, w, h), cgImage);
    
            assert( CFGetRetainCount(cgImage) == 1 );
    
            CGColorSpaceRelease(colorSpace);
            CGContextRelease(cgContext);
            CGImageRelease(cgImage);
        }
    }
    


    表面 :它来自以前的私有框架 表面 .
    CIContext 有功能 render: ... toIOSurface: .
    IOSurfaceRef


    CGContextDrawImage / ?
    有一种方法可以禁用缓存吗?
    3.为什么会发生缓存?
    4.我可以使用一些较低级别(非私有)的API手动清理系统内存吗?

    欢迎提出任何建议。

    2 回复  |  直到 6 年前
        1
  •  5
  •   Michael Allman    6 年前

    回答你的第二个问题,

    Is there a way to disable caching at render?

    设置环境变量 CI_SURFACE_CACHE_CAPACITY 设置为0将或多或少禁用 CIContext 表面缓存。此外,可以通过将该变量设置为以字节为单位的给定值来指定自定义(近似)缓存限制。例如,设置 至2147483648指定2 GiB的表面缓存限制。

    请注意,似乎一个进程的所有 CIContext .

        2
  •  1
  •   E.Coms    6 年前

    [ciContext

    没有这样的90M缓存。也许这就是你想要的。

    enter image description here