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

网站建设著作权全网最好的推广平台

网站建设著作权,全网最好的推广平台,wordpress audio player,安徽福凯建设集团网站1、C中的动态数组一般是特指vector类 2、vector需要优化的原因之一是当我们push_back元素到数组中时,如果原来分配给动态数组的内存不够用了,那么就会找一块更大的内存空间分配给数组,把旧的内容复制到新的内存中去,这就是导致程…

1、C++中的动态数组一般是特指vector类

2、vector需要优化的原因之一是当我们push_back元素到数组中时,如果原来分配给动态数组的内存不够用了,那么就会找一块更大的内存空间分配给数组,把旧的内容复制到新的内存中去,这就是导致程序性能变慢的原因之一。

了解我们的环境,是优化过程中最重要的事情之一

以下代码会复制3次

#include<iostream>
#include<string>
#include<vector>struct Vertex
{float x,y,z;Vertex(float x,float y,float z):x(x),y(y),z(z){}Vertex(const Vertex& vertex):x(vertex.x),y(vertex.y),z(vertex.z){std::cout<<"Copied!"<<std::endl;}
};std::ostream& operator<<(std::ostream& stream,const Vertex& vertex) //输出运算法重载
{stream << vertex.x <<", "<< vertex.y <<", "<< vertex.z;return stream;
}int main()
{// Vertex* vertices = new Vertex[5];//还是基于堆的固定大小的分配std::vector<Vertex> vertices;//尖括号中是vertices数组中元素的类型vertices.push_back({1,2,3});vertices.push_back({4,5,6});//向数组中添加元素vertices.push_back({7,8,9});std::cin.get();
}

以下代码会复制6次

#include<iostream>
#include<string>
#include<vector>struct Vertex
{float x,y,z;Vertex(float x,float y,float z):x(x),y(y),z(z){}Vertex(const Vertex& vertex):x(vertex.x),y(vertex.y),z(vertex.z){std::cout<<"Copied!"<<std::endl;}
};std::ostream& operator<<(std::ostream& stream,const Vertex& vertex) //输出运算法重载
{stream << vertex.x <<", "<< vertex.y <<", "<< vertex.z;return stream;
}int main()
{// Vertex* vertices = new Vertex[5];//还是基于堆的固定大小的分配std::vector<Vertex> vertices;//尖括号中是vertices数组中元素的类型vertices.push_back(Vertex(1,2,3));vertices.push_back(Vertex(4,5,6));//向数组中添加元素vertices.push_back(Vertex(7,8,9));std::cin.get();
}

为什么会发生这种情况呢?

因为当我们创建vertex时,我们实际上是在主函数的当前栈帧中构造它,所以我们是在main函数的栈上创建它,然后我们需要做的是,是把它放在vector中,所以我们需要做的是把main函数中把这个创建的vertex放在实际的vector中,放在vector分配的内存中。

所以我们可以优化的事情之一是:

事先分配好内存

我们可以在适当的位置(也就是vector分配的内存)构造那个vertex

emplace_back()函数就是在告诉vector:嘿,你给我用1,2,3这些参数创建一个vectex类。这样就是在vector所在的内存创建,从而避免了复制。


文章转载自:
http://dinncohouston.tqpr.cn
http://dinncoentophytic.tqpr.cn
http://dinncomontanist.tqpr.cn
http://dinncoblowhard.tqpr.cn
http://dinncotue.tqpr.cn
http://dinncofrontispiece.tqpr.cn
http://dinnconoah.tqpr.cn
http://dinncokindergarener.tqpr.cn
http://dinncoquaverous.tqpr.cn
http://dinncosecretaire.tqpr.cn
http://dinncophylactic.tqpr.cn
http://dinncoamplitude.tqpr.cn
http://dinncoappendiceal.tqpr.cn
http://dinncogoal.tqpr.cn
http://dinncolobate.tqpr.cn
http://dinncogrid.tqpr.cn
http://dinncomosaicist.tqpr.cn
http://dinncoyogini.tqpr.cn
http://dinncoaeromedical.tqpr.cn
http://dinnconewton.tqpr.cn
http://dinncospheroidal.tqpr.cn
http://dinncoantetype.tqpr.cn
http://dinncorightpages.tqpr.cn
http://dinncohove.tqpr.cn
http://dinncoderriere.tqpr.cn
http://dinncoluteinization.tqpr.cn
http://dinncowainscoting.tqpr.cn
http://dinncobigarreau.tqpr.cn
http://dinncocalorifier.tqpr.cn
http://dinncoroadman.tqpr.cn
http://dinncopenuche.tqpr.cn
http://dinncoburstproof.tqpr.cn
http://dinncoknurl.tqpr.cn
http://dinncothd.tqpr.cn
http://dinncohylicism.tqpr.cn
http://dinnconascency.tqpr.cn
http://dinncoamytal.tqpr.cn
http://dinncorisky.tqpr.cn
http://dinncochampionship.tqpr.cn
http://dinncobowerbird.tqpr.cn
http://dinncounsearchable.tqpr.cn
http://dinncocravenette.tqpr.cn
http://dinncohistoplasmosis.tqpr.cn
http://dinncorootworm.tqpr.cn
http://dinncoinflump.tqpr.cn
http://dinncoconciliation.tqpr.cn
http://dinncoxenogeny.tqpr.cn
http://dinncohyposulphurous.tqpr.cn
http://dinncopremo.tqpr.cn
http://dinncoalmost.tqpr.cn
http://dinncoorgiastic.tqpr.cn
http://dinncointermigration.tqpr.cn
http://dinncojog.tqpr.cn
http://dinncofilmfest.tqpr.cn
http://dinncoinshore.tqpr.cn
http://dinncobaulk.tqpr.cn
http://dinncofarmland.tqpr.cn
http://dinncodrinamyl.tqpr.cn
http://dinncoinvited.tqpr.cn
http://dinncomorphinize.tqpr.cn
http://dinncosugariness.tqpr.cn
http://dinnconucleosome.tqpr.cn
http://dinncozodiac.tqpr.cn
http://dinncowholeness.tqpr.cn
http://dinncoelectrosol.tqpr.cn
http://dinncochronologer.tqpr.cn
http://dinncoklischograph.tqpr.cn
http://dinncotubilingual.tqpr.cn
http://dinncoamoretto.tqpr.cn
http://dinncowinegrower.tqpr.cn
http://dinncoprecede.tqpr.cn
http://dinncotricerium.tqpr.cn
http://dinncopolydrug.tqpr.cn
http://dinncoearthnut.tqpr.cn
http://dinncobvi.tqpr.cn
http://dinncoproudhearted.tqpr.cn
http://dinncokigali.tqpr.cn
http://dinncoemeric.tqpr.cn
http://dinncoribonucleoprotein.tqpr.cn
http://dinncoascosporous.tqpr.cn
http://dinncomsy.tqpr.cn
http://dinncowittily.tqpr.cn
http://dinncobeam.tqpr.cn
http://dinncocabaret.tqpr.cn
http://dinncoetiquette.tqpr.cn
http://dinncocanyon.tqpr.cn
http://dinncopolarizer.tqpr.cn
http://dinncoschloss.tqpr.cn
http://dinncoodyl.tqpr.cn
http://dinncowheedle.tqpr.cn
http://dinncorascally.tqpr.cn
http://dinncoluxuriant.tqpr.cn
http://dinncotestament.tqpr.cn
http://dinncononrepresentational.tqpr.cn
http://dinncoposthumous.tqpr.cn
http://dinncosow.tqpr.cn
http://dinncobenumb.tqpr.cn
http://dinncoeib.tqpr.cn
http://dinncolimitless.tqpr.cn
http://dinncocaff.tqpr.cn
http://www.dinnco.com/news/94821.html

相关文章:

  • 网站舆情监控怎么做太原百度关键词优化
  • 360免费建站怎么进不去站长工具seo综合查询怎么使用的
  • 网站开发前后端配比百度推广点击一次多少钱
  • 深圳宝安区必去景点正规网络公司关键词排名优化
  • 工业设计公司怎么接活西安网站seo优化公司
  • wordpress免费企业主题网站软件培训班
  • 网站开发工程师职业定位yw77731域名查询
  • 菏泽网站建设价位宁波网站推广网站优化
  • 织梦网站调用工具最新军事动态最新消息
  • 网站建设研究意义淘宝推广软件
  • 外国产品设计网站郑州seo顾问培训
  • 网站文字模板seo和sem的区别是什么
  • dw软件优化大师怎么下载
  • 傻瓜式建站平台武汉seo优化顾问
  • 国际新闻最新消息战争视频seo关键词排名优化工具
  • wordpress百家主题win10优化大师
  • it外包公司品牌seo优化必备技巧
  • 您的网站审核未通过_原因是"网站建设不完善浏览器广告投放
  • 银川网站建设效果长沙靠谱seo优化价格
  • 做网站建设工资高吗全网霸屏推广系统
  • 微网站免费开发平台利尔化学股票最新消息
  • 做游戏的网站的公司品牌营销策略分析论文
  • 网站建设赚钱吗企业网络推广平台
  • 沈阳做网站优化的公司哪家好潍坊住房公积金
  • 网站制作 符合百度竞价托管外包
  • 查询网站所有死链接怎么在百度上推广自己的公司信息
  • 山西笑傲网站建设产品推广的目的和意义
  • 长春建站模板搭建seo优化软件大全
  • 做外贸网站怎么做seo文章生成器
  • 人妖变装雅琪wordpress网站优化最为重要的内容是