关于malloc函数的问题
当malloc函数的输入参数为正数的情况下,有哪些情况可能导致malloc函数发生异常呢?
[解决办法]
地址空间不够用了。
[解决办法]
频繁的分配1M一下的小空间,可能造成堆碎片过多,分配失败
分配超过10M的空间,有些设备上会因内存不足而分配失败
[解决办法]
没有连续的空间满足你的要求
[解决办法]
malloc不会抛出异常,直会return NULL。并设置errno
具体设置的错误,你要查编译器手册
In Visual C++ 2005, malloc sets errno to ENOMEM if a memory allocation fails or if the amount of memory requested exceeds _HEAP_MAXREQ. For information on this and other error codes, see errno, _doserrno, _sys_errlist, and _sys_nerr.
[解决办法]