首页 > 解决方案 > 如何判断哪些对 malloc 的调用失败?

问题描述

我这里的内存是一个 32 字节的数组,地址从 0 到 31,当且仅当内存中有 n+1 个连续的可用字节时,对 malloc(n) 的调用才会成功

1: malloc(2)
2: free(1)
3: malloc(14)
4: free(1)
5: malloc(2)
6: free(1)
7: malloc(11)
8: malloc(6)
9: malloc(11)
10: free(20)
11: malloc(6)
12: malloc(14)
13: malloc(13)
14: malloc(1)
15: free(27)
16: malloc(2)
17: malloc(5)
18: malloc(1)
19: free(27)
20: free(20)

我主要是寻求帮助以了解如何判断哪个失败而不是哪个失败,如果这是有道理的,谢谢!

标签: memorymalloc

解决方案


推荐阅读