帮公司做网站的外包公司,怎么在word添加wordpress,创建企业,wordpress html伪静态c中的内存的分配和释放是由程序员自己规划。智能指针不需要自己去delete一个new的对象#xff0c;会自动释放对应的内存空间。unique_ptr#xff1a;作用域指针#xff0c;超出作用域后自动释放分配的内存区域。unique是指唯一#xff0c;不能复制一个unique_ptr指针#…c中的内存的分配和释放是由程序员自己规划。智能指针不需要自己去delete一个new的对象会自动释放对应的内存空间。unique_ptr作用域指针超出作用域后自动释放分配的内存区域。unique是指唯一不能复制一个unique_ptr指针因为如果复制一个unique_ptr指针则这两个指针指向同样的内存 当一个指针释放该区域的内存另一个复制的指针就会指向一块被释放的内存地址。 #include iostream
#include string
#include memoryclass Entity
{
public:int x, y;Entity(){std::cout 这是构造函数 std::endl;}~Entity(){std::cout 这是析构函数 std::endl;}
}; int main()
{{//std::unique_ptrEntity e(new Entity());//异常安全会对构造函数抛出的异常进行捕获std::unique_ptrEntity e std::make_uniqueEntity();}std::cin.get();return 0;
} shared_ptr共享指针shared_ptr工作方式是通过引用计数跟踪指针的引用数量当引用计数为0时释放内存。 #include iostream
#include string
#include memoryclass Entity
{
public:int x, y;Entity(){std::cout 这是构造函数 std::endl;}~Entity(){std::cout 这是析构函数 std::endl;}
}; int main()
{{std::shared_ptrEntity e2;{std::shared_ptrEntity e1 std::make_sharedEntity();e2 e1;}}std::cin.get();return 0;
} weak_ptr:j结合share_ptr使用weak_ptr不会增加引用计数。但share_ptr会增加应用计数。 #include iostream
#include string
#include memoryclass Entity
{
public:int x, y;Entity(){std::cout 这是构造函数 std::endl;}~Entity(){std::cout 这是析构函数 std::endl;}
}; int main()
{{std::weak_ptrEntity w;{std::shared_ptrEntity e1 std::make_sharedEntity();w e1;}}std::cin.get();return 0;
}