智能指针为内存管理带来了挺大的便利,不过相比传统指针到底慢了多少,是本文要探讨的。
首先上测试代码
====================================================
#include <iostream>
#include <ctime>
#include <sys/timeb.h>
#include <boost/shared_array.hpp>
using namespace std;
time_t getms()
{
timeb tb;
ftime(&tb);
return (int)(tb.time*1000 + tb.millitm);
}
int main()
{
int times = 1000000000;
{
int* p = new int[100];
time_t oldtime = getms();
for (int i = 0; i < times; ++ i)
{
int* a = p;
a[0] = i;