[英]What are reasons for “Cannot allocate memory” except of exceeding address space and memory fragmentation?
問題是在 Mac OS XI 上的 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 */
memory 分配模式是這樣的:
我已經檢查過這些 memory 塊都沒有泄漏,所以我猜想在任何給定時間使用的 memory 都保持在 1GB 以下,應該可以在 32 位系統上訪問。
第二個猜測是 memory 碎片。 但是我已經檢查了步驟 3 中的所有塊都重用了相同的地址。 所以我接觸不到 1GB 的 memory - memory 碎片應該不是問題。
現在我完全失去了不分配 memory 的原因。 當我處理少於 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
那么“無法分配內存”的其他原因是什么,我該如何診斷它們? 或者可能我在排除上述原因時犯了錯誤,那么我該如何再次檢查它們?
原來我犯了一個錯誤,檢查地址空間沒有用完。 我應該使用vmmap
而不是使用heap
命令。 vmmap
顯示大部分 memory 被映射到 memory 的圖像使用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.