qt中函数
void* __cdecl malloc(
In _CRT_GUARDOVERFLOW size_t _Size
);
malloc()在内存的动态存储区中分配一块长度为size字节的连续区域。参数size为需要的内存空间的长度,返回该区域的地址。
malloc 中size_t的大小
(0-4,294,967,296)
#ifdef _WIN64
typedef unsigned __int64 size_t;
#else
typedef unsigned int size_t;
#endif
内存分配测试代码
char *memory1 = reinterpret_cast<char*>(malloc(1024 * 1024 * 1024 * 1 * sizeof (char)));
char *memory2 = reinterpret_cast<char*>(malloc(1024 * 1024 * 1024 * 3 * sizeof (char)));
if(memory1 == nullptr) {
qDebug() << "malloc memory1 failed";
} else {
qDebug() << "malloc memory1 OK";
}
if(memory2 == nullptr) {
qDebug() << "malloc memory2 failed";
} else {
qDebug() << "malloc memory2 OK";
}
free(memory1);
free(memory2);