问题是在Mac OS X上的32位应用程序中我收到错误
malloc: *** mmap(size=49721344) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
参考错误代码在sys / errno.h中:
#define ENOMEM 12 /* Cannot allocate memory */
内存分配模式如下:
我已经检查过这些内存块都没有泄漏,所以我猜在任何给定时间使用的内存都要低于1GB,这应该可以在32位系统上访问。
第二个猜测是内存碎片。但是我已经检查过步骤3中的所有块都重用了相同的地址。所以我触摸不到1GB的内存 - 内存碎片应该不是问题。
现在我完全迷失了不能分配内存的原因。当处理少于27张图像时,一切正常。以下是步骤6之前26个映像的堆命令结果的一部分:
Process 1230: 4 zones
Zone DefaultMallocZone_0x273000: Overall size: 175627KB; 29620 nodes malloced for 68559KB (39% of capacity); largest unused: [0x6f800000-8191KB]
Zone DispatchContinuations_0x292000: Overall size: 4096KB; 1 nodes malloced for 1KB (0% of capacity); largest unused: [0x2600000-1023KB]
Zone QuartzCore_0x884400: Overall size: 232KB; 7039 nodes malloced for 132KB (56% of capacity); largest unused: [0x3778ca0-8KB]
Zone DefaultPurgeableMallocZone_0x27f2000: Overall size: 4KB; 0 nodes malloced for 0KB (0% of capacity); largest unused: [0x3723000-4KB]
All zones: 36660 nodes malloced - 68691KB
对于27张图片:
Process 1212: 4 zones
Zone DefaultMallocZone_0x273000: Overall size: 167435KB; 30301 nodes malloced for 68681KB (41% of capacity); largest unused: [0x6ea51000-32372KB]
Zone DispatchContinuations_0x292000: Overall size: 4096KB; 1 nodes malloced for 1KB (0% of capacity); largest unused: [0x500000-1023KB]
Zone QuartzCore_0x106b000: Overall size: 192KB; 5331 nodes malloced for 101KB (52% of capacity); largest unused: [0x37f2f98-8KB]
Zone DefaultPurgeableMallocZone_0x30f8000: Overall size: 4KB; 0 nodes malloced for 0KB (0% of capacity); largest unused: [0x368f000-4KB]
All zones: 35633 nodes malloced - 68782KB
那么“无法分配内存”的其他原因是什么?如何诊断它们?或者我可能犯了一个错误,排除了上述原因,那么我该如何再次检查它们呢?
答案 0 :(得分:2)
原来我错误地检查地址空间是否已用尽。我应该使用heap
而不是vmmap
命令。 vmmap
显示大部分内存被映射到内存中的图像使用。