大神,求救!!为什么delete要比new慢?
class CMatrix1
{
public:
double matrix[16];
CMatrix1()
{
}
~CMatrix1()
{
};
};
//测试
{
DWORD tickCount = 0;
char tempStr[1024] = {0};
//1. 赋值
tickCount = GetTickCount();
std::vector<CMatrix1*> matrixList;
matrixList.resize(264633);
for (int i = 0; i < 264633; i ++)
{
CMatrix1 *des = new CMatrix1;
matrixList[i] = des;
}
tickCount = GetTickCount() - tickCount;
memset(tempStr,0,1024);
sprintf(tempStr,"segment paras new: %d s", tickCount/1000);
OutputLogString(tempStr); //写文件函数,用于调试输出
//2. 析构
tickCount = GetTickCount();
for (int i = 264632; i >=0 ; i --)
{
delete matrixList[i];
}
tickCount = GetTickCount() - tickCount;
memset(tempStr,0,1024);
sprintf(tempStr,"segment paras delete: %d s", tickCount/1000);
OutputLogString(tempStr);
}
{
public:
double matrix[16];
CMatrix1()
{
}
~CMatrix1()
{
};
};
//测试
{
DWORD tickCount = 0;
char tempStr[1024] = {0};
//1. 赋值
tickCount = GetTickCount();
std::vector<CMatrix1*> matrixList;
matrixList.resize(264633);
for (int i = 0; i < 264633; i ++)
{
CMatrix1 *des = new CMatrix1;
matrixList[i] = des;
}
tickCount = GetTickCount() - tickCount;
memset(tempStr,0,1024);
sprintf(tempStr,"segment paras new: %d s", tickCount/1000);
OutputLogString(tempStr); //写文件函数,用于调试输出
//2. 析构
tickCount = GetTickCount();
for (int i = 264632; i >=0 ; i --)
{
delete matrixList[i];
}
tickCount = GetTickCount() - tickCount;
memset(tempStr,0,1024);
sprintf(tempStr,"segment paras delete: %d s", tickCount/1000);
OutputLogString(tempStr);
}
...全文
相关推荐
new,delete和指针
new,delete和指针实例讲解
C++中new/delete与new[]/delete[]的使用区别
编写代码,举例说明new/delete与new[]/delete[]在创建对象时申请内存,以及释放空间时的区别
C++ 使用new与delete需注意的原则
主要介绍了C++ 使用new与delete需注意的原则,帮助大家更好的理解和学习c++,感兴趣的朋友可以了解下
C++动态内存分配(new/new[]和delete/delete[])详解
主要介绍了C++动态内存分配(new/new[]和delete/delete[])详解的相关资料,需要的朋友可以参考下
C++中new和delete的介绍
今天小编就为大家分享一篇关于C++中new和delete的介绍,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧


