【发布时间】:2014-03-24 18:51:16
【问题描述】:
我正在为我正在开发的库编写单元测试。无法模拟库实现。单元测试是在程序内存不足时返回一个特殊值。
我想出了这个幼稚的解决方案:
// Fillup memory
int *p = NULL
do {
p = malloc(sizeof(int));
// store p somewhere to release it later
} while(p);
// Got out of memory :)
有没有比这个解决方案更快地填满内存的方法不增加使用 malloc 分配的内存块大小?
PS:禁止使用第三方内存分配器:)
【问题讨论】:
标签: unit-testing out-of-memory c99