首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

侧对内存的有关问题

2012-02-17 
侧对内存的问题#includeiostream.hvoidmain(){long *array[10000]longi0long sum0array[i]new lon

侧对内存的问题
#include<iostream.h>
void main()
{long *array[10000];
 long i=0;
 long sum=0;
  array[i]=new long [100000];
  while(array[i]!=NULL)
{sum+=sizeof(long)*100000;
i++;
array[i]=new long [100000];
  cout<<sum<<"bytes"<<endl;
}
  cout<<sum<<"bytes"<<endl;
  delete []array[i];
  cout<<endl;
}
为什么根据建立的不同数组大小,测出来的对内存的值不同啊 


[解决办法]
delete []array[i];

你这里内存泄露啊。
[解决办法]
array[i]=new long [100000]; 
while(array[i]!=NULL) 
 {sum+=sizeof(long)*100000; //不断的分配
 i++; 
 array[i]=new long [100000]; 
cout < <sum < <"bytes" < <endl; 
 } 

delete []array[i]; 

删除却这样删 利用循环来删吧




[解决办法]

探讨
delete []array[i];

你这里内存泄露啊。

热点排行