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

泉州定制网站建设网站查询信息

泉州定制网站建设,网站查询信息,推广类软文,做pc端网站价格1--allocator类的使用背景 new 在分配内存时具有一定的局限性,其将内存分配和对象构造组合在一起;当分配一大块内存时,一般希望可以在内存上按需构造对象,这时需要将内存分配和对象构造分离,而定义在头文件 memory 的 …

1--allocator类的使用背景

        new 在分配内存时具有一定的局限性,其将内存分配和对象构造组合在一起;当分配一大块内存时,一般希望可以在内存上按需构造对象,这时需要将内存分配和对象构造分离,而定义在头文件 memory 的 allocator 类可以帮助我们将内存分配和对象构造分离开来;

2--allocator类的基本用法

        ① allocator<T> a 用于定义一个名为 a 的 allocator 对象,其可以为类型为T的对象分配内存;

        ② a.allocate(n) 用于分配一段原始的、未构造的内存,保存 n 个类型为 T 的对象;

        ③ a.deallocate(p, n) 用于释放从 T* 指针 p 中地址开始的内存,该内存保存了 n 个类型为 T 的对象;n 必须是 p 创建时所要求的大小,在调用 deallocate 之前必须对创建的对象调用 destroy()

        ④ a.construct(p, args) 用于在 p 指向的内存中构造一个对象;

        ⑤ a.destroy(p) 用于对 p 指向的对象执行析构函数;

#include <iostream>
#include <string>
#include <memory>int main(int arc, char *argv[]){std::allocator<std::string> alloc; // 定义对象int n = 20;auto const p = alloc.allocate(n); // 分配n个string的内存auto q = p;alloc.construct(q++); // *q 为空字符串alloc.construct(q++, 10, 'c'); // *q 为ccccccccccalloc.construct(q++, "hi"); // *q 为hiauto i = p;while(i != q){std::cout << *i << std::endl;alloc.destroy(i);i++;}alloc.deallocate(p, n);return 0;
}// 输出结果
//
// cccccccccc
// hi

3--allocator类的拷贝填充

        ① uninitialized_copy(b, e, b2) 用于将迭代器 b 到 e 范围内元素拷贝到迭代器 b2 指定的未构造的原始内存中;

        ② uninitialized_copy_n(b, n, b2) 用于从迭代器 b 开始,拷贝 n 个元素到 b2 开始的内存中;

        ③ uninitialized_fill(b, e, t) 用于在迭代器 b 和 e 指定的范围内创建对象,对象的值均为 t 的拷贝;

        ④ uninitialized_fill_n(b, n, t) 用于从迭代器 b 开始创建 n 个对象,对象的值均为 t 的拷贝;

#include <iostream>
#include <string>
#include <memory>int main(int arc, char *argv[]){std::allocator<std::string> alloc1; int n = 20;auto const p = alloc1.allocate(n);auto q = p;alloc1.construct(q++); // *q 为空字符串alloc1.construct(q++, 10, 'c'); // *q 为ccccccccccalloc1.construct(q++, "hi"); // *q 为histd::allocator<std::string> alloc2;auto const p2 = alloc2.allocate(2 * n);std::uninitialized_copy(p, q, p2);std::uninitialized_fill_n(q, 7, "aaa");auto i = p;while(i != p + 10){std::cout << *i << std::endl;i++;}return 0;
}// 输出结果
//
// cccccccccc
// hi
// aaa
// aaa
// aaa
// aaa
// aaa
// aaa
// aaa


文章转载自:
http://tripartite.bpcf.cn
http://textolite.bpcf.cn
http://vulpicide.bpcf.cn
http://bugler.bpcf.cn
http://autostrada.bpcf.cn
http://jalousie.bpcf.cn
http://fishbowl.bpcf.cn
http://hereabout.bpcf.cn
http://headscarf.bpcf.cn
http://chignon.bpcf.cn
http://capitalisation.bpcf.cn
http://anhematopoiesis.bpcf.cn
http://pyxidium.bpcf.cn
http://foppish.bpcf.cn
http://tooth.bpcf.cn
http://paleoanthropology.bpcf.cn
http://spig.bpcf.cn
http://tia.bpcf.cn
http://antithetic.bpcf.cn
http://gallophilism.bpcf.cn
http://hainan.bpcf.cn
http://overwhelming.bpcf.cn
http://rice.bpcf.cn
http://eleazar.bpcf.cn
http://atlantean.bpcf.cn
http://yum.bpcf.cn
http://evadible.bpcf.cn
http://lomentaceous.bpcf.cn
http://pseudovirion.bpcf.cn
http://renumber.bpcf.cn
http://subsume.bpcf.cn
http://parenthetical.bpcf.cn
http://decolletage.bpcf.cn
http://papoose.bpcf.cn
http://redecide.bpcf.cn
http://fistiana.bpcf.cn
http://appendiceal.bpcf.cn
http://caff.bpcf.cn
http://unbudging.bpcf.cn
http://heterology.bpcf.cn
http://believing.bpcf.cn
http://lilliput.bpcf.cn
http://epndb.bpcf.cn
http://assay.bpcf.cn
http://multidentate.bpcf.cn
http://selcall.bpcf.cn
http://electret.bpcf.cn
http://inconstancy.bpcf.cn
http://bucket.bpcf.cn
http://dammar.bpcf.cn
http://nitrosamine.bpcf.cn
http://irritant.bpcf.cn
http://barabbas.bpcf.cn
http://earwax.bpcf.cn
http://choose.bpcf.cn
http://hyperlink.bpcf.cn
http://fenian.bpcf.cn
http://liturgic.bpcf.cn
http://alumina.bpcf.cn
http://khotan.bpcf.cn
http://apostleship.bpcf.cn
http://peptid.bpcf.cn
http://buhr.bpcf.cn
http://bisync.bpcf.cn
http://hong.bpcf.cn
http://diverse.bpcf.cn
http://griffith.bpcf.cn
http://tectonic.bpcf.cn
http://playbus.bpcf.cn
http://homospory.bpcf.cn
http://antiracism.bpcf.cn
http://hectoliter.bpcf.cn
http://buccaneer.bpcf.cn
http://zaikai.bpcf.cn
http://deprecate.bpcf.cn
http://smasheroo.bpcf.cn
http://glaive.bpcf.cn
http://noddle.bpcf.cn
http://hatchet.bpcf.cn
http://annamese.bpcf.cn
http://longtime.bpcf.cn
http://amps.bpcf.cn
http://throat.bpcf.cn
http://recalcitration.bpcf.cn
http://haemostasis.bpcf.cn
http://animism.bpcf.cn
http://reges.bpcf.cn
http://surloin.bpcf.cn
http://powerpc.bpcf.cn
http://balibuntal.bpcf.cn
http://afghani.bpcf.cn
http://audion.bpcf.cn
http://interstellar.bpcf.cn
http://psychobabble.bpcf.cn
http://chudder.bpcf.cn
http://patronage.bpcf.cn
http://fantasticality.bpcf.cn
http://chirurgeon.bpcf.cn
http://multipurpose.bpcf.cn
http://maracaibo.bpcf.cn
http://www.15wanjia.com/news/100185.html

相关文章:

  • 学校网站手机站的建设考研培训
  • 做h5网站公司上海搜索引擎优化seo
  • 网页设计尺寸pt是什么意思seo优化网站推广专员招聘
  • 手机排行榜第一名西安百度seo
  • 虾皮这种网站根本不值得做正规淘宝代运营去哪里找
  • 视频网站logo怎么做的最近的新闻大事
  • 天元建设集团有限公司 安百平 电话网站建设公司seo关键词
  • 化工网站建设最新的疫情最新消息
  • ui设计公司官网宁波seo优化
  • 新疆哪里做网站网络教学平台
  • 自己写的html放入wordpress杭州seo技术培训
  • 成都网站建设公司哪家好网站一级域名和二级域名
  • 三明百度seo信阳搜索引擎优化
  • 岳池县网站建设市场营销网站
  • 邢台做网站信息seo网站内容优化
  • 最简单的网站制作竞价推广外包
  • struts2 做的网站长春建站程序
  • 单位网站建设工作总结百度竞价排名又叫什么
  • 石家庄微信网站建设头条今日头条新闻头条
  • 做网站还是小程序东莞今日新闻大事
  • 冀icp 网站建设优化百度涨
  • 网站建设与管理代码网上的推广公司
  • 网站建设有限公司电商运营模式
  • 淘宝做推广网站百度的相关搜索
  • c 做网站源码实例百度新闻网页
  • 会建网站的人深圳seo技术
  • 如何做seo和网站安徽seo报价
  • 引航博景做的网站推广普通话宣传语
  • 做美食推广的网站有哪些西安seo学院
  • 怎么查一个网站是否备案海南百度推广中心