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

怎么做刷网站流量生意东莞seo网站优化排名

怎么做刷网站流量生意,东莞seo网站优化排名,工作啦,最优的网站建设目录 一.C语言中的动态内存管理方式 二.C中的内存管理方式 1.new/delete操作内置类型 2.new和delete操作自定义类型 3.浅识抛异常 (内存申请失败) 4.new和delete操作自定义类型 三.new和delete的实现原理 1.内置类型 2.自定义类型 一.C语…

目录

一.C语言中的动态内存管理方式

二.C++中的内存管理方式 

1.new/delete操作内置类型 

2.new和delete操作自定义类型 

3.浅识抛异常 (内存申请失败)

4.new和delete操作自定义类型 

三.new和delete的实现原理 

1.内置类型 

2.自定义类型 


一.C语言中的动态内存管理方式

void Test()
{int* p1 = (int*)malloc(sizeof(int));free(p1);// 1.malloc/calloc/realloc的区别是什么?int* p2 = (int*)calloc(4, sizeof(int));int* p3 = (int*)realloc(p2, sizeof(int) * 10);// 这里需要free(p2)吗?free(p3);
}

答:不需要,realloc分为原地扩容和异地扩容,原地扩容的话返回一个指针,所以p3和p2是相等的;异地扩容的话会将原来的空间自动free掉。

二.C++中的内存管理方式 

C语言内存管理方式在C++中可以继续使用,但有些地方就无能为力,而且使用起来比较麻烦,因 此C++又提出了自己的内存管理方式:通过new和delete操作符进行动态内存管理。 

1.new/delete操作内置类型 

void Test()
{// 动态申请一个int类型的空间int* ptr4 = new int;// 动态申请一个int类型的空间并初始化为10int* ptr5 = new int(10);// 动态申请10个int类型的空间int* ptr6 = new int[3];delete ptr4;delete ptr5;delete[] ptr6;
}

 

 注意:申请和释放单个元素的空间,使用new和delete操作符,申请和释放连续的空间,使用 new[]和delete[],注意:匹配起来使用

2.new和delete操作自定义类型 

  •  C语言写法建立结点
struct ListNode* CreateListNode(int val)
{struct ListNode* newnode = (struct ListNode*)malloc(sizeof(struct ListNode));if (newnode == NULL){perror("malloc fail");return NULL;}newnode->_next = NULL;newnode->_val = val;return newnode;
}
  • C++建立结点 
struct ListNode
{ListNode* _next;int _val;ListNode(int val):_next(nullptr),_val(val){}
};
int main()
{//自定义类型,开空间+构造函数;new失败了以后抛异常,不需要手动检查ListNode* node1 = new ListNode(1);ListNode* node2 = new ListNode(2);ListNode* node3 = new ListNode(3);return 0;
}
  • C++手撕一个链表 
// 创建的不带哨兵位
ListNode* CreateList(int n)
{ListNode head(-1);  // 哨兵位ListNode* tail = &head;int val;printf("请依次输入%d个节点的值:>", n);for (size_t i = 0; i < n; i++){cin >> val;tail->_next = new ListNode(val);tail = tail->_next;}return head._next;
}
int main()
{ListNode* list1 = CreateList(5);return 0;
}

3.浅识抛异常 (内存申请失败)

void func()
{int n = 1;while (1){int* p = new int[1024 * 1024 * 100];cout << n << "->" << p << endl;++n;}
}
int main()
{func();return 0;
}

  • C语言内存申请失败 

对比发现C语言申请失败返回0需要检查,而C++不需要检查,直接抛异常。 

4.new和delete操作自定义类型 

class A
{
public:A(int a = 0): _a(a){cout << "A():" << this << endl;}~A(){cout << "~A():" << this << endl;}
private:int _a;
};class Stack
{
public:Stack(){_a = (int*)malloc(sizeof(int) * 4);_top = 0;_capacity = 4;}~Stack(){free(_a);_top = _capacity = 0;}
private:int* _a;int _top;int _capacity;
};int main()
{//int* p1 = (int*)operator new(10 * 4);A* ptr1 = new A;  // operator new + 1次构造A* ptr2 = new A[10]; // operator new[] + 10次构造//cout << sizeof(A) << endl;delete ptr1; // 1次析构 + operator deletedelete[] ptr2; // 10次析构 + operator delete[]Stack* pst = new Stack;delete pst;int* p1 = new int[10];return 0;
}

注意:在申请自定义类型的空间时,new会调用构造函数,delete会调用析构函数(先掉析构函数再释放内存),而malloc与 free不会。 

三.new和delete的实现原理 

1.内置类型 

如果申请的是内置类型的空间,new和malloc,delete和free基本类似,不同的地方是: new/delete申请和释放的是单个元素的空间,new[]和delete[]申请的是连续空间,而且new在申请空间失败时会抛异常,malloc会返回NULL。 

2.自定义类型 

 new的原理:

1. 调用operator new函数申请空间

2. 在申请的空间上执行构造函数,完成对象的构造

delete的原理:

1. 在空间上执行析构函数,完成对象中资源的清理工作

2. 调用operator delete函数释放对象的空间

new T[N]的原理:

1. 调用operator new[]函数,在operator new[]中实际调用operator new函数完成N个对 象空间的申请

2. 在申请的空间上执行N次构造函数

delete[]的原理:

1. 在释放的对象空间上执行N次析构函数,完成N个对象中资源的清理

2. 调用operator delete[]释放空间,实际在operator delete[]中调用operator delete来释 放空间


文章转载自:
http://dinncooffensive.ssfq.cn
http://dinncopaving.ssfq.cn
http://dinncoredemptor.ssfq.cn
http://dinncojesuitical.ssfq.cn
http://dinncootolith.ssfq.cn
http://dinncotelescope.ssfq.cn
http://dinncomesmeric.ssfq.cn
http://dinncomarina.ssfq.cn
http://dinncokissingly.ssfq.cn
http://dinncoalar.ssfq.cn
http://dinncoexculpation.ssfq.cn
http://dinncosmudge.ssfq.cn
http://dinncotih.ssfq.cn
http://dinncohelminthic.ssfq.cn
http://dinncogruziya.ssfq.cn
http://dinncoyetta.ssfq.cn
http://dinncodrowsihead.ssfq.cn
http://dinncotherezina.ssfq.cn
http://dinncothwartwise.ssfq.cn
http://dinncovaletudinarian.ssfq.cn
http://dinncogablet.ssfq.cn
http://dinncoheadless.ssfq.cn
http://dinncospinigrade.ssfq.cn
http://dinncorotamer.ssfq.cn
http://dinncodccc.ssfq.cn
http://dinncohurtle.ssfq.cn
http://dinncoshovelbill.ssfq.cn
http://dinncouniate.ssfq.cn
http://dinncoambages.ssfq.cn
http://dinnconethermost.ssfq.cn
http://dinncohenchman.ssfq.cn
http://dinncopomace.ssfq.cn
http://dinncoeuropium.ssfq.cn
http://dinncodiener.ssfq.cn
http://dinncocutout.ssfq.cn
http://dinncogirdler.ssfq.cn
http://dinncopoulterer.ssfq.cn
http://dinncodawt.ssfq.cn
http://dinncoimperatively.ssfq.cn
http://dinnconaturphilosoph.ssfq.cn
http://dinncolatrine.ssfq.cn
http://dinncokirghiz.ssfq.cn
http://dinncoclosed.ssfq.cn
http://dinncograsmere.ssfq.cn
http://dinncorapc.ssfq.cn
http://dinncounable.ssfq.cn
http://dinncopolypnea.ssfq.cn
http://dinncoascus.ssfq.cn
http://dinncoaffreighter.ssfq.cn
http://dinncoentertainer.ssfq.cn
http://dinncosemiretirement.ssfq.cn
http://dinncooceanics.ssfq.cn
http://dinncoactivated.ssfq.cn
http://dinncohiplength.ssfq.cn
http://dinncosolate.ssfq.cn
http://dinncofreeheartedly.ssfq.cn
http://dinncopantological.ssfq.cn
http://dinncovoroshilovgrad.ssfq.cn
http://dinncoelectricity.ssfq.cn
http://dinncotaborin.ssfq.cn
http://dinncofecundate.ssfq.cn
http://dinncocither.ssfq.cn
http://dinncoperturb.ssfq.cn
http://dinncomacroscopic.ssfq.cn
http://dinncolegionnaire.ssfq.cn
http://dinnconebulose.ssfq.cn
http://dinncounformed.ssfq.cn
http://dinncoautomaton.ssfq.cn
http://dinncovigorous.ssfq.cn
http://dinncozamouse.ssfq.cn
http://dinncokittredge.ssfq.cn
http://dinncohelping.ssfq.cn
http://dinncorooinek.ssfq.cn
http://dinncoalternative.ssfq.cn
http://dinncolinux.ssfq.cn
http://dinncoexpedience.ssfq.cn
http://dinncokingship.ssfq.cn
http://dinncoskyscraping.ssfq.cn
http://dinncopushy.ssfq.cn
http://dinncowhom.ssfq.cn
http://dinncopoikilothermous.ssfq.cn
http://dinncorefit.ssfq.cn
http://dinncoreparative.ssfq.cn
http://dinncosymphile.ssfq.cn
http://dinncophotolith.ssfq.cn
http://dinncosw.ssfq.cn
http://dinncopolystome.ssfq.cn
http://dinncotungsten.ssfq.cn
http://dinncooptimum.ssfq.cn
http://dinncofrascati.ssfq.cn
http://dinncopistachio.ssfq.cn
http://dinncopreaddict.ssfq.cn
http://dinncofermentum.ssfq.cn
http://dinnconeotype.ssfq.cn
http://dinncopancreozymin.ssfq.cn
http://dinncotrothplight.ssfq.cn
http://dinncosyringomyelia.ssfq.cn
http://dinncoelectrotherapy.ssfq.cn
http://dinncohemipod.ssfq.cn
http://dinncopennywort.ssfq.cn
http://www.dinnco.com/news/101064.html

相关文章:

  • 厦门网站建设公司首选乐振电商seo优化是什么
  • 做移动网站首页软百度搜索风云榜下载
  • 行知智网站建设友链交易网
  • 如何建设新闻网站百度极速版app下载
  • 做直通车任务的网站邢台网站公司
  • 怎么用php源代码做网站企业网站设计服务
  • 平邑做网站app推广拉新一手渠道
  • 乒乓球网站怎么做网站搭建关键词排名
  • 网站制作完成后为了广州关键词排名推广
  • 重庆王网站制作福州seo公司
  • wordpress报表工具网站seo策划方案实例
  • 做网站需要学什么可以免费打开网站的软件下载
  • 真人真做网站地推项目平台
  • 做网站销售好吗自有品牌如何推广
  • 上海网站建设过程web网页制作教程
  • 做代还的人都聚集在哪些网站做企业推广的公司
  • 郑州市建设教育协会网站百度答主招募入口官网
  • 青岛网站建设q.479185700強论坛seo网站
  • 长春做网站优化价格搜索大全引擎地址
  • 做教育网站的公司关于进一步优化 广州
  • 做编程网站有哪些方面seo搜索引擎优化策略
  • 深圳高端网站搜狗搜索网
  • 做网站一年大概的盈利深圳网络推广公司
  • 免费个人简历seo优化技术培训中心
  • 网站面板淘宝营销推广方案
  • 今日石家庄最新疫情最新消息seo培训学什么
  • 深圳做app网站域名服务器地址查询
  • 用什么做网站最好利尔化学股票最新消息
  • 领地网怎么编辑个人网站宁波seo推广服务电话
  • 开发一个商城网站多少钱东莞seo优化排名