高手给我做下这个C程序。悬赏100!

来源:百度知道 编辑:UC知道 时间:2024/04/27 08:59:40
编写一个测试程序,使用用malloc函数,找出Win2000一次最多能分配多少内存,总共
能分配多少内存。注意:要在Release下运行,不然很慢。

临时做了两个,不知对不对,你自己测下,数再改的大点容易出结果.单位我不知搞的对不!

// 测试分配内存数
#include <stdio.h>
#include <malloc.h>
#include <iostream.h>
int main()
{
int *p;
long MemorySize=0;
while (true)
{
p = (int*)malloc(sizeof(int)*1024);
if (p != NULL)
{
MemorySize=MemorySize + sizeof(int);
cout << "已申请内存数:" << MemorySize << " M" << endl;
}
else
{
//cout << "最多申请内存总数为:" << MemorySize-sizeof(int) << " M" << endl; 此时可能无法响应
exit(1);
}
return 0;
}

// 测试最大分配内存
#include <stdio.h>
#include <malloc.h>
#include <iostream.h>
int main()
{
int *p;
long MemorySize=0;
while (true)
{
MemorySize=MemorySize+10240000;
p = (int*)malloc(sizeof(int)*MemorySize);
if (p != NULL)