当前位置: 首页 > news >正文

电商网站开发设计方案有哪些免费做网站怎么做网站吗

电商网站开发设计方案有哪些,免费做网站怎么做网站吗,织梦免费企业模板网站,wordpress twenty fourteen主题做的演示网站1、概念 堆内存的对象需要手动使用delete销毁,如果忘记使用delete销毁就会造成内存泄漏。 所以C在ISO 98标注中引入了智能指针的概念,并在C11 中趋于完善。 使用智能指针可以让堆内存对象具有栈内存对象的特性。原理时给需要自动回收的堆内存对象套上一层…

1、概念

堆内存的对象需要手动使用delete销毁,如果忘记使用delete销毁就会造成内存泄漏。

所以C++在ISO 98标注中引入了智能指针的概念,并在C++11 中趋于完善。

使用智能指针可以让堆内存对象具有栈内存对象的特性。原理时给需要自动回收的堆内存对象套上一层栈内存的模板类对象即可。

C++有四种智能指针:

  • auto_ptr (自动指针,已经废弃)(C++ISO 98)
  • unique_ptr (唯一指针)(C++ISO 11)
  • shared_ptr (共享指针)(C++ISO 11)
  • weak_ptr (协助指针)(C++ISO 11)

使用智能指针需要引入头文件#include<memory>

2、auto_ptr

#include <iostream>
#include <memory>
using namespace std;
class Test
{
private:
    string s;
public:
    Test(string s):s(s)
    {
        cout << s << "构造函数" << endl;
    }
    ~Test()
    {
        cout << s << "析构函数" << endl;
    }
    void show()
    {
        cout << s << "执行程序" << endl;
    }
};
int main()
{
    {
        Test *t1 = new Test("A");
        // 创建一个智能指针管理t1
        auto_ptr<Test> ap1(t1); // ap1 管理t1
        // 取出被管理的堆内存对象,并调用show成员函数
        ap1.get()->show(); 
        // 释放控制权
//        ap1.release();
        // 创建B堆对象,B将A顶掉,A对象销毁
        ap1.reset(new Test("B"));
        ap1.get()->show();        // 释放控制权并且销毁资源对象
        ap1.reset();
        cout << "局部代码块执行结束" << endl;
    }
    return 0;
}

释放对象不会调用析构函数,只有销毁对象才会有

由于成员变量存在指针类型,因此拷贝构造函数与赋值运算符的使用会出现问题。与浅拷贝的问题不同的是,auto_ptr的复制语义会引起资源对象控制权转移的问题。

#include <iostream>
#include <memory>
using namespace std;
class Test
{
private:
    string s;
public:
    Test(string s):s(s)
    {
        cout << s << "构造函数" << endl;
    }
    ~Test()
    {
        cout << s << "析构函数" << endl;
    }
    void show()
    {
        cout << s << "执行程序" << endl;
    }
};int main()
{
    {
        Test *t1 = new Test("A");
        // 创建一个智能指针管理t1
        auto_ptr<Test> ap1(t1); // ap1 管理t1
        auto_ptr<Test> ap2(ap1);    // 显式调用拷贝构造函数
        cout << ap1.get() << " " << ap2.get() << endl; // 0 0x1052780
        auto_ptr<Test> ap3 = ap2;   // 隐式调用构造函数
        // 0 0 0xe82780
        cout << ap1.get() << " " << ap2.get() << " " << ap3.get() << endl;
        auto_ptr<Test> ap4;
        ap4 = ap3;  // 赋值运算符
        // 0 0 0 0x922780
        cout << ap1.get() << " " << ap2.get() <<
                " " << ap3.get() << " " << ap4.get() << endl;    }
    return 0;
}

3、unique_ptr

作为对auto_ptr的改进,unique_ptr对其他持有的资源对象具有唯一控制权,即不可以通过常规的复制语义转移或拷贝资源对象的控制权。

通过特殊的语法实现控制权的转移效果。

#include <iostream>
#include <memory>using namespace std;class Test
{
private:string s;
public:Test(string s):s(s){
        cout << s << "构造函数" << endl;}~Test(){
        cout << s << "析构函数" << endl;}void show(){
        cout << s << "执行程序" << endl;}
};int main()
{{
        Test *t1 = new Test("A");// 创建一个智能指针管理t1unique_ptr<Test> up1(t1); // up1 管理t1unique_ptr<Test> up2(move(up1));    // 显式调用拷贝构造函数
        cout << up1.get() << " " << up2.get() << endl; // 0 0x1052780unique_ptr<Test> up3 = move(up2);   // 隐式调用构造函数// 0 0 0xe82780
        cout << up1.get() << " " << up2.get() << " " << up3.get() << endl;unique_ptr<Test> up4;
        up4 = move(up3);  // 赋值运算符// 0 0 0 0x922780
        cout << up1.get() << " " << up2.get() <<" " << up3.get() << " " << up4.get() << endl;}return 0;
}

4、shared_ptr

unique_ptr对资源具有独占性,多个shared_ptr对象可以共享资源。

shared_ptr有两种创建方式:

两种创建方式的区别在于后者是一步到位(创建资源对象+关系绑定),前者分为两步完成(先创建资源对象,再进行关系绑定)。

新方式的优点:

  • 安全性更好
  • 性能更好

新方式的缺点:

  • 资源释放效率低

每多一个shared_ptr对资源进行管理,引用计数将+1,每个指向该对象的shared_ptr对象销毁时,引用计数-1,最后一个shared_ptr对象销毁时,计数清零,资源对象销毁。

#include <iostream>
#include <memory>
using namespace std;
class Test
{
private:string s;
public:Test(string s):s(s){
        cout << s << "构造函数" << endl;}~Test(){
        cout << s << "析构函数" << endl;}void show(){
        cout << s << "执行程序" << endl;}
};
int main()
{shared_ptr<Test> sp3;{shared_ptr<Test> sp1 = make_shared<Test>("A");
        cout << "引用计数:" << sp1.use_count() << endl;shared_ptr<Test> sp2(sp1); // 拷贝构造函数
        cout << "引用计数:" << sp2.use_count() << endl;        sp3 = sp2;
        cout << "引用计数:" << sp3.use_count() << endl;}
    cout << "引用计数:" << sp3.use_count() << endl;return 0;
}

5、weak_ptr

weak_ptr是一个不控制资源对象的智能指针,也不会影响资源的引用计数,其主要目的是协助shared_ptr工作。

通过weak_ptr的构造函数,参数传入一个持有资源对象的shared_ptr对象或者weak_ptr对象即可创建。

weak_ptr与资源对象呈现弱相关性,所以不支持get等函数直接操作资源对象。

建议weak_ptr调用lock函数之前,先检测引用计数是否大于0,或使用expried()函数检测是否可以转换为shared_ptr。

lock()函数,通过传入持有资源对象的对象创建新对象

#include <iostream>
#include <memory>
using namespace std;
class Test
{
private:string s;
public:Test(string s):s(s){
        cout << s << "构造函数" << endl;}~Test(){
        cout << s << "析构函数" << endl;}void show(){
        cout << s << "执行程序" << endl;}
};
int main()
{weak_ptr<Test> wp3;{shared_ptr<Test> sp1 = make_shared<Test>("A");weak_ptr<Test> wp1 = sp1;
        cout << sp1.use_count() << endl; // 1
        cout << wp1.use_count() << endl; // 1weak_ptr<Test> wp2(wp1); // 拷贝构造
        cout << wp2.use_count() << endl;shared_ptr<Test> sp2 = wp1.lock();
        cout << sp2.use_count() << endl; // 2        wp3 = wp2;
        cout << wp3.use_count() << endl;}
    cout << wp3.use_count() << endl; // 0if(wp3.expired()){
        cout << "无法使用lock函数,因为没有可以管理的对象" << endl;}return 0;
}


文章转载自:
http://dinncoharborage.ssfq.cn
http://dinncounminished.ssfq.cn
http://dinncosort.ssfq.cn
http://dinncowunderkind.ssfq.cn
http://dinncoadvocation.ssfq.cn
http://dinncoparamedian.ssfq.cn
http://dinncoternary.ssfq.cn
http://dinncoendhand.ssfq.cn
http://dinncoorganosilicon.ssfq.cn
http://dinncochelator.ssfq.cn
http://dinnconoctambulism.ssfq.cn
http://dinncoantic.ssfq.cn
http://dinncoacapriccio.ssfq.cn
http://dinncounaffected.ssfq.cn
http://dinncodeflect.ssfq.cn
http://dinncofrankenstein.ssfq.cn
http://dinncomildew.ssfq.cn
http://dinncoindivertible.ssfq.cn
http://dinncosetaceous.ssfq.cn
http://dinncotrompe.ssfq.cn
http://dinncoseparability.ssfq.cn
http://dinncozollverein.ssfq.cn
http://dinncocolorado.ssfq.cn
http://dinncotestudinal.ssfq.cn
http://dinncocarborane.ssfq.cn
http://dinncotelescript.ssfq.cn
http://dinncomsam.ssfq.cn
http://dinncoflutist.ssfq.cn
http://dinncotransonic.ssfq.cn
http://dinncocataract.ssfq.cn
http://dinncoincapacious.ssfq.cn
http://dinncodisannex.ssfq.cn
http://dinncosensuously.ssfq.cn
http://dinncodowntrend.ssfq.cn
http://dinncoatabrine.ssfq.cn
http://dinncoosteophyte.ssfq.cn
http://dinncoonomastics.ssfq.cn
http://dinncoassociateship.ssfq.cn
http://dinncoheterozygosity.ssfq.cn
http://dinncosubmontane.ssfq.cn
http://dinncosiphonein.ssfq.cn
http://dinncohotelkeeper.ssfq.cn
http://dinncoauspex.ssfq.cn
http://dinncoacrawl.ssfq.cn
http://dinncotickie.ssfq.cn
http://dinncoslantindicular.ssfq.cn
http://dinncocolicin.ssfq.cn
http://dinncoresettle.ssfq.cn
http://dinncofeastful.ssfq.cn
http://dinncoempathize.ssfq.cn
http://dinncocoastwise.ssfq.cn
http://dinncoobit.ssfq.cn
http://dinncounwilled.ssfq.cn
http://dinncoanubis.ssfq.cn
http://dinncopushover.ssfq.cn
http://dinncomyxoid.ssfq.cn
http://dinncoassuan.ssfq.cn
http://dinncofavonian.ssfq.cn
http://dinncoairstop.ssfq.cn
http://dinncoabeyant.ssfq.cn
http://dinncoaposteriori.ssfq.cn
http://dinncoroamer.ssfq.cn
http://dinncorettery.ssfq.cn
http://dinncocashmere.ssfq.cn
http://dinncodatal.ssfq.cn
http://dinncopuntil.ssfq.cn
http://dinncopolydactyl.ssfq.cn
http://dinncohermes.ssfq.cn
http://dinncoparnassian.ssfq.cn
http://dinncopseudocoelomate.ssfq.cn
http://dinncopaleotemperature.ssfq.cn
http://dinncobaculine.ssfq.cn
http://dinncotally.ssfq.cn
http://dinncosolubility.ssfq.cn
http://dinncoirinite.ssfq.cn
http://dinncofletcher.ssfq.cn
http://dinncounconducive.ssfq.cn
http://dinncoawanting.ssfq.cn
http://dinncojiujitsu.ssfq.cn
http://dinncosmolt.ssfq.cn
http://dinncoimagist.ssfq.cn
http://dinncohardhearted.ssfq.cn
http://dinnconicish.ssfq.cn
http://dinncodoorless.ssfq.cn
http://dinncocitole.ssfq.cn
http://dinncomeanspirited.ssfq.cn
http://dinncothecodont.ssfq.cn
http://dinncojosser.ssfq.cn
http://dinncohepplewhite.ssfq.cn
http://dinncorectum.ssfq.cn
http://dinncotruncation.ssfq.cn
http://dinncoglobulin.ssfq.cn
http://dinncoglyptograph.ssfq.cn
http://dinncomegadyne.ssfq.cn
http://dinncophotophobia.ssfq.cn
http://dinncobollox.ssfq.cn
http://dinncoambilingnal.ssfq.cn
http://dinncoasunder.ssfq.cn
http://dinncoaccessible.ssfq.cn
http://dinncoyeshivah.ssfq.cn
http://www.dinnco.com/news/112510.html

相关文章:

  • 湖南做网站 地址磐石网络关键词搜索推广
  • 网站新闻怎么写网络营销推广方式
  • 导航网站织梦模板福州seo代理商
  • 网站建设规划建议免费软文发布平台
  • 创意合肥网站建设搜索引擎的两个基本方法
  • 网站建设平台用乐云践新百度贴吧官网网页
  • 适合前端做项目的网站在线制作网站免费
  • 濮阳做网站的公司seo竞价
  • 网站模板 哪家好宁波seo在线优化哪家好
  • 如何做某网站的移动客户端开发交换链接
  • 360做企业网站多少钱互联网广告行业
  • 记事本怎么做网站图片链接sem竞价代运营公司
  • 如需郑州网站建设seo优化软件
  • 做网络写手赚钱的网站关键词包括哪些内容
  • it外包公司是做什么的重庆自动seo
  • 沈阳网站推广企业网站是什么
  • 公司网站建设说明书拼多多seo是什么意思
  • 网站建设入门百度指数分析平台
  • 陕西省建设注册中心网站可以推广的平台
  • 做软件页面设计的软件seo任务平台
  • iis部署网站无法访问关键词seo培训
  • 做3d动画视频接私活的网站广州seo工程师
  • 门户类型的网站怎样做推广更有效
  • 北京网站备案流程入门seo技术教程
  • 收费网站设计竞价网站推广
  • seo网站做推广的公司腾讯企业邮箱
  • 网络传媒公司怎么运营四川seo关键词工具
  • 盐城网站建设建站seo的中文意思
  • 网络营销方案怎么做石家庄百度seo排名
  • 淘宝做标题网站百度热搜广告设计公司