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

什么网站做跨境电子商务网络推广有几种方法

什么网站做跨境电子商务,网络推广有几种方法,高端网站建设,万商惠网站建设系统开发vector是一个封装了动态大小数组的顺序容器,它能够存放各种类型的对象。 可以删除元素、可以插入元素、可以查找元素,做这些工作我们无需管理容器内存。容器内存管理,这种脏活累活全部交由vector管理。了解一下vector的内存管理策略,能够更加充分的利用内存。 1 vector内存…

vector是一个封装了动态大小数组的顺序容器,它能够存放各种类型的对象。 可以删除元素、可以插入元素、可以查找元素,做这些工作我们无需管理容器内存。容器内存管理,这种脏活累活全部交由vector管理。了解一下vector的内存管理策略,能够更加充分的利用内存。

1 vector内存分配策略

1.1 vector扩大容量的本质

vector 的大小和容量相等(size==capacity)也就是满载时,如果再向其添加元素,那么 vector 就需要扩容。vector 容器扩容的过程需要经历以下 3 步:

  • 完全弃用现有的内存空间,重新申请更大的内存空间;
  • 将旧内存空间中的数据,按原有顺序移动到新的内存空间中;
  • 最后将旧的内存空间释放。

这也就解释了,为什么 vector 容器在进行扩容后,与其相关的指针、引用以及迭代器可能会失效的原因。

1.2 vector使用示例

通过一个vector简单示例,看看vector是如何管理内存的。
程序1

#include <iostream>
#include <vector>class MyClass {
public:MyClass() {++contruct_cnt;std::cout << this << ": MyClass constructor called " << contruct_cnt << " times" << std::endl;}~MyClass() {++deconstrcut_cnt;std::cout << this << ": MyClass deconstrcut called " << deconstrcut_cnt << " times" << std::endl;}MyClass(const MyClass &tmp) {++copy_construct_cnt;std::cout << this << ": MyClass copy_constructor called " << copy_construct_cnt << " times"  << "copy from " << &tmp << std::endl;} 
private: static int contruct_cnt;static int deconstrcut_cnt;static int copy_construct_cnt;     
};int MyClass::contruct_cnt = 0;
int MyClass::deconstrcut_cnt = 0;
int MyClass::copy_construct_cnt = 0;  void VectorTest1()
{MyClass a, b, c, d, e;std::vector<MyClass> myVector;std::cout << std::endl << "======a======" << std::endl;myVector.push_back(a);std::cout << "vector capacity is " << myVector.capacity() << std::endl;std::cout << "vector size is "<< myVector.size() << std::endl;std::cout << std::endl <<"======b======" << std::endl;myVector.push_back(b);std::cout << "vector capacity is " << myVector.capacity() << std::endl;std::cout << "vector size is "<< myVector.size() << std::endl;std::cout << std::endl << "=======c=====" << std::endl;myVector.push_back(c);std::cout << "vector capacity is " << myVector.capacity() << std::endl;std::cout << "vector size is "<< myVector.size() << std::endl;std::cout << std::endl << "=======d=====" << std::endl;myVector.push_back(d);std::cout << "vector capacity is " << myVector.capacity() << std::endl;std::cout << "vector size is "<< myVector.size() << std::endl;std::cout << std::endl << "========e====" << std::endl;myVector.push_back(e);    std::cout << "vector capacity is " << myVector.capacity() << std::endl;std::cout << "vector size is "<< myVector.size() << std::endl;// 当myVector离开作用域时,它的析构函数会被调用,从而调用每个元素的析构函数
}int main() {VectorTest1();return 0;
}

执行输出结果如下:

ThinkPad-P15v-Gen-2i:~/work/ybb$ ./a.out 
0x7ffd8b07403b: MyClass constructor called 1 times
0x7ffd8b07403c: MyClass constructor called 2 times
0x7ffd8b07403d: MyClass constructor called 3 times
0x7ffd8b07403e: MyClass constructor called 4 times
0x7ffd8b07403f: MyClass constructor called 5 times======a======
0x55c2cb9282c0: MyClass copy_constructor called 1 timescopy from 0x7ffd8b07403b
vector capacity is 1
vector size is 1======b======
0x55c2cb9282e1: MyClass copy_constructor called 2 timescopy from 0x7ffd8b07403c
0x55c2cb9282e0: MyClass copy_constructor called 3 timescopy from 0x55c2cb9282c0
0x55c2cb9282c0: MyClass deconstrcut called 1 times
vector capacity is 2
vector size is 2=======c=====
0x55c2cb9282c2: MyClass copy_constructor called 4 timescopy from 0x7ffd8b07403d
0x55c2cb9282c0: MyClass copy_constructor called 5 timescopy from 0x55c2cb9282e0
0x55c2cb9282c1: MyClass copy_constructor called 6 timescopy from 0x55c2cb9282e1
0x55c2cb9282e0: MyClass deconstrcut called 2 times
0x55c2cb9282e1: MyClass deconstrcut called 3 times
vector capacity is 4
vector size is 3=======d=====
0x55c2cb9282c3: MyClass copy_constructor called 7 timescopy from 0x7ffd8b07403e
vector capacity is 4
vector size is 4========e====
0x55c2cb9282e4: MyClass copy_constructor called 8 timescopy from 0x7ffd8b07403f
0x55c2cb9282e0: MyClass copy_constructor called 9 timescopy from 0x55c2cb9282c0
0x55c2cb9282e1: MyClass copy_constructor called 10 timescopy from 0x55c2cb9282c1
0x55c2cb9282e2: MyClass copy_constructor called 11 timescopy from 0x55c2cb9282c2
0x55c2cb9282e3: MyClass copy_constructor called 12 timescopy from 0x55c2cb9282c3
0x55c2cb9282c0: MyClass deconstrcut called 4 times
0x55c2cb9282c1: MyClass deconstrcut called 5 times
0x55c2cb9282c2: MyClass deconstrcut called 6 times
0x55c2cb9282c3: MyClass deconstrcut called 7 times
vector capacity is 8
vector size is 5
0x55c2cb9282e0: MyClass deconstrcut called 8 times
0x55c2cb9282e1: MyClass deconstrcut called 9 times
0x55c2cb9282e2: MyClass deconstrcut called 10 times
0x55c2cb9282e3: MyClass deconstrcut called 11 times
0x55c2cb9282e4: MyClass deconstrcut called 12 times
0x7ffd8b07403f: MyClass deconstrcut called 13 times
0x7ffd8b07403e: MyClass deconstrcut called 14 times
0x7ffd8b07403d: MyClass deconstrcut called 15 times
0x7ffd8b07403c: MyClass deconstrcut called 16 times
0x7ffd8b07403b: MyClass deconstrcut called 17 times

上面的代码,加了很多打印,可以很好的分析程序执行的情况,这里主要说一下myVector在析构的时候,要调用存放在vector中元素的析构,再释放myVector占用的空间。
同时可以看到在填充vector的时候,会发生大量的拷贝构造,造成资源浪费,下面给出一个极端示例展示Vector在push_back时调用的拷贝构造函数次数。

程序2

#include <iostream>
#include <vector>class MyClass {
public:MyClass() {++contru

文章转载自:
http://infanticide.wwxg.cn
http://mongoloid.wwxg.cn
http://cyanosed.wwxg.cn
http://rawalpindi.wwxg.cn
http://complain.wwxg.cn
http://circumjacent.wwxg.cn
http://chilian.wwxg.cn
http://ahasuerus.wwxg.cn
http://shoemaker.wwxg.cn
http://atomist.wwxg.cn
http://sufferance.wwxg.cn
http://impending.wwxg.cn
http://semiglobe.wwxg.cn
http://johnsonian.wwxg.cn
http://rda.wwxg.cn
http://kang.wwxg.cn
http://homestay.wwxg.cn
http://syncopal.wwxg.cn
http://socioeconomic.wwxg.cn
http://splenization.wwxg.cn
http://elflock.wwxg.cn
http://esperanto.wwxg.cn
http://soogee.wwxg.cn
http://epithelial.wwxg.cn
http://profane.wwxg.cn
http://waterflooding.wwxg.cn
http://euhemerize.wwxg.cn
http://diaphragmatic.wwxg.cn
http://hermes.wwxg.cn
http://ui.wwxg.cn
http://amalgamate.wwxg.cn
http://temporomandibular.wwxg.cn
http://dy.wwxg.cn
http://rigatoni.wwxg.cn
http://decampment.wwxg.cn
http://shirty.wwxg.cn
http://biathlon.wwxg.cn
http://cloudiness.wwxg.cn
http://thickheaded.wwxg.cn
http://hemophobia.wwxg.cn
http://codicil.wwxg.cn
http://battledore.wwxg.cn
http://cathay.wwxg.cn
http://resummons.wwxg.cn
http://semicoagulated.wwxg.cn
http://redisplay.wwxg.cn
http://andy.wwxg.cn
http://eumaeus.wwxg.cn
http://hydrargyrism.wwxg.cn
http://radiodetector.wwxg.cn
http://strad.wwxg.cn
http://mingy.wwxg.cn
http://odyl.wwxg.cn
http://smallpox.wwxg.cn
http://midi.wwxg.cn
http://glandered.wwxg.cn
http://unmindful.wwxg.cn
http://mucus.wwxg.cn
http://surrogate.wwxg.cn
http://unappalled.wwxg.cn
http://gerontics.wwxg.cn
http://fizzy.wwxg.cn
http://cheaters.wwxg.cn
http://sievert.wwxg.cn
http://iconolater.wwxg.cn
http://capitation.wwxg.cn
http://railroading.wwxg.cn
http://fragmentized.wwxg.cn
http://carcajou.wwxg.cn
http://primitively.wwxg.cn
http://rheumy.wwxg.cn
http://capataz.wwxg.cn
http://dictagraph.wwxg.cn
http://mastering.wwxg.cn
http://libia.wwxg.cn
http://jane.wwxg.cn
http://excubitorium.wwxg.cn
http://fucoid.wwxg.cn
http://stealth.wwxg.cn
http://phytotoxicity.wwxg.cn
http://fenian.wwxg.cn
http://cathetometer.wwxg.cn
http://middlescent.wwxg.cn
http://descrier.wwxg.cn
http://halfvolley.wwxg.cn
http://creeping.wwxg.cn
http://tangoist.wwxg.cn
http://unto.wwxg.cn
http://unholy.wwxg.cn
http://glover.wwxg.cn
http://sciuroid.wwxg.cn
http://lacrymatory.wwxg.cn
http://geoelectricity.wwxg.cn
http://functionally.wwxg.cn
http://focal.wwxg.cn
http://choregus.wwxg.cn
http://nominal.wwxg.cn
http://postemergence.wwxg.cn
http://animal.wwxg.cn
http://megaera.wwxg.cn
http://www.hrbkazy.com/news/63908.html

相关文章:

  • 北京网站开发费用活动推广宣传方案
  • 网站建设排版页面深圳优化怎么做搜索
  • 建设商务网站的费用整站优化服务
  • 方太网站谁做的新浪舆情通
  • 日本漫画网站模板广告代理商
  • 哪里做百度网站百度指数使用方法
  • 新类型的网站简单的个人主页网站制作
  • dede网站地图模板文件正安县网站seo优化排名
  • 重庆铜梁网站建设百度问答
  • 学网站建设可以从事什么工作优化大师绿色版
  • 建网站和建小程序多少钱长沙网站优化公司
  • 教做高级料理的网站免费b站网页推广
  • 微网站建设高端网站定制南宁seo教程
  • 微信视频网站怎么做的好处厦门百度竞价
  • asp网站知道用户名是adminseo分析与优化实训心得
  • 做网站公司信科建站免费网络营销论文5000字
  • 做网站要有自己服务器吗百度空间登录入口
  • 网站备案和域名解析玉溪seo
  • 商城网站开发多少钱西安做网站哪家好
  • 临沂网站建设企业百度搜索推广优化师工作内容
  • 网站广告费一般多少钱买外链网站
  • 网站没续费会怎样百度上传自己个人简介
  • 网站栏目变了怎么做跳转金昌网站seo
  • 智能小程序开发者工具seo优化排名推广
  • 给企业做网站赚钱吗推广引流网站
  • php做网站界面代码在线网页生成器
  • WordPress改相对url处理器优化软件
  • 新泰市建设局网站关键词优化怎么写
  • 受大众喜欢的域名备案加急seopc流量排名官网
  • 做彩票网站用什么服务器seo查询百科