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

苏宁易购网站建设的目标seo如何优化网站步骤

苏宁易购网站建设的目标,seo如何优化网站步骤,做前端常用的网站及软件,效果图公司排名前言:之前看过侯老师的《STL源码剖析》但是那已经是多年以前的,现在工作中有时候查问题和崩溃都需要了解实际工作中使用到的STL的实现。因此计划把STL的源码再过一遍。   摘要:本文描述了llvm中libcxx的std::vector的实现。   关键字&…

  前言:之前看过侯老师的《STL源码剖析》但是那已经是多年以前的,现在工作中有时候查问题和崩溃都需要了解实际工作中使用到的STL的实现。因此计划把STL的源码再过一遍。
  摘要:本文描述了llvm中libcxx的std::vector的实现。
  关键字vector
  其他:参考代码LLVM-libcxx

  vector是标准库中的连续存储的容器,也就是容器中说任意两个索引上相邻的元素的地址也是相邻的,可以通过索引随机访问。vector中的元素默认是通过堆内存管理的,在进行空间分配时一般会比时机需求的空间要大,即capacity_size,这样能够避免在插入元素时频繁申请内存导致的性能问题(如果频繁申请内存导致页置换的话还是很耗时的)。

1 vector

  先看下容器的定义,和其他容器一样都是一个模板类。_Tp就是类型,而_Allocator是进行内存管理的分配器,默认分配器就是通过::operator new::operator delete申请和释放内存的。

template <class _Tp, class _Allocator /* = allocator<_Tp> */>
class _LIBCPP_TEMPLATE_VIS vector

  vector的内存布局比较简单如下图,有三个指针分别指向了对应的开始地址,已使用部分的尾地址,申请到的内存的尾地址,[__begin_, __end_)之间是已经使用的内存部分,[__end_, __end_cap_)是申请了但是未使用的部分(保留这一部分是为了避免插入元素时频繁allocate而可能出现的性能问题。)
在这里插入图片描述

private:pointer __begin_ = nullptr;pointer __end_ = nullptr;__compressed_pair<pointer, allocator_type> __end_cap_ =__compressed_pair<pointer, allocator_type>(nullptr, __default_init_tag());

构造和销毁
  vector的构造比较简单,就是先通过allocator申请一块内存,然后通过for循环逐个构造对象。构造时通过for循环实现,由于没有利用CPU的一些SMID指令的优化,必然效率不是很好。

vector(size_type __n, const value_type& __x, const allocator_type& __a) : __end_cap_(nullptr, __a){std::__debug_db_insert_c(this);if (__n > 0){__vallocate(__n);__construct_at_end(__n, __x);}
}vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x){_ConstructTransaction __tx(*this, __n);const_pointer __new_end = __tx.__new_end_;for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) {__alloc_traits::construct(this->__alloc(), std::__to_address(__pos), __x);}
}

  销毁就比较直接,通过一个包装器__destroy_vector,先clear再调用deallocate释放内存。

__vec_.__clear();
__alloc_traits::deallocate(__vec_.__alloc(), __vec_.__begin_, __vec_.capacity());;

clear
  clear函数只会针对析构容器中的每一个函数并不会释放当前容器中的内存。因此在进行容器释放时需要注意,如果期望释放内存的话可以通过vector().swap(vec)的方式或者在调用clear之后调用shrink_to_fit 调整内存大小。

void clear() _NOEXCEPT{size_type __old_size = size();__clear();__annotate_shrink(__old_size);  //看源码里面什么也不会做std::__debug_db_invalidate_all(this);
}void __clear() _NOEXCEPT {__base_destruct_at_end(this->__begin_);}
void __base_destruct_at_end(pointer __new_last) _NOEXCEPT {pointer __soon_to_be_end = this->__end_;while (__new_last != __soon_to_be_end)          //依然是一个完整的循环析构__alloc_traits::destroy(__alloc(), std::__to_address(--__soon_to_be_end));this->__end_ = __new_last;
}

push_back
  push_back时,如果当前有足够的的大小则会在尾部构建一个对象,扩容的大小是按照现有大小的2倍来,即std::min(max_size(), std::max(current_cap + 1, 2 * current_cap)),简单的理解就是在条件允许的情况下扩容2倍。

void vector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x){allocator_type& __a = this->__alloc();//__split_buffer就是一个包装器__split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);// __v.push_back(std::forward<_Up>(__x));__alloc_traits::construct(__a, std::__to_address(__v.__end_), std::forward<_Up>(__x));__v.__end_++;__swap_out_circular_buffer(__v);//这个函数没有干什么就是将__v中的size设置给当前的vector
}

emplace_back
  emplace_backpush_back基本相同都是向容器中插入元素,如果对于插入vector::value_type类型的对象二者是没有区别的,push_back也实现了右值的重载,不存在push_back对于右值会多次拷贝的情况。主要的区别是emplace_back通过可变参数模板将参数直接传递给了构建器也就意味着同样的代码emplace_back直接在对应的内存上构建对象,而相比之下push_back是先构建再拷贝。

void vector<_Tp, _Allocator>::emplace_back(_Args&&... __args)

resize
  resize的实现比较直接,内存小了就扩容,大了就析构但是并不释放内存。

void vector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x){size_type __cs = size();if (__cs < __sz)this->__append(__sz - __cs, __x);else if (__cs > __sz)this->__destruct_at_end(this->__begin_ + __sz);//只会析构对象,不会释放内存
}

shrink_to_fit
  

vector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT{if (__external_cap_to_internal(size()) > __cap()){vector(*this, allocator_type(__alloc())).swap(*this);}
}

vector<bool>基本上被建议放弃使用了,所以就不深入了。

2 array

  array的实现比较简单就是一个简单的栈数组的包装器。就不详细描述了。

template <class _Tp, size_t _Size>
struct _LIBCPP_TEMPLATE_VIS array
{// types:typedef array __self;typedef _Tp                                   value_type;typedef value_type&                           reference;typedef const value_type&                     const_reference;typedef value_type*                           iterator;typedef const value_type*                     const_iterator;typedef value_type*                           pointer;typedef const value_type*                     const_pointer;typedef size_t                                size_type;typedef ptrdiff_t                             difference_type;typedef _VSTD::reverse_iterator<iterator>       reverse_iterator;typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;_Tp __elems_[_Size];
};

3 参考文献

  • stackoverflow——push_back vs emplace_back
  • Proposed Wording for Placement Insert

文章转载自:
http://dinncomanx.zfyr.cn
http://dinncocycloheximide.zfyr.cn
http://dinncoqic.zfyr.cn
http://dinncocursely.zfyr.cn
http://dinncoisallobar.zfyr.cn
http://dinncoyetorofu.zfyr.cn
http://dinncothermodynamic.zfyr.cn
http://dinncobrumaire.zfyr.cn
http://dinncostupa.zfyr.cn
http://dinncofourbagger.zfyr.cn
http://dinncoinspirational.zfyr.cn
http://dinncocoverlet.zfyr.cn
http://dinncoconsolidation.zfyr.cn
http://dinncobuddha.zfyr.cn
http://dinncokuchen.zfyr.cn
http://dinncolongstanding.zfyr.cn
http://dinncobrotherhood.zfyr.cn
http://dinncogroundsill.zfyr.cn
http://dinncolongbill.zfyr.cn
http://dinncoconsentient.zfyr.cn
http://dinncosambal.zfyr.cn
http://dinncowenceslas.zfyr.cn
http://dinncowatkins.zfyr.cn
http://dinncowpm.zfyr.cn
http://dinncoshipment.zfyr.cn
http://dinncohanefiyeh.zfyr.cn
http://dinncotriumvir.zfyr.cn
http://dinncohibernacula.zfyr.cn
http://dinncocosmos.zfyr.cn
http://dinncocringingly.zfyr.cn
http://dinncosouvlaki.zfyr.cn
http://dinncosicko.zfyr.cn
http://dinncointuit.zfyr.cn
http://dinncosideburns.zfyr.cn
http://dinncodealate.zfyr.cn
http://dinncotriploblastic.zfyr.cn
http://dinncoinfector.zfyr.cn
http://dinncouniparous.zfyr.cn
http://dinncowarrison.zfyr.cn
http://dinncowhomp.zfyr.cn
http://dinncononagon.zfyr.cn
http://dinncocontraprop.zfyr.cn
http://dinncoeditorialist.zfyr.cn
http://dinncoroutinier.zfyr.cn
http://dinncopanetella.zfyr.cn
http://dinncooutsmart.zfyr.cn
http://dinncohorizon.zfyr.cn
http://dinncoapologia.zfyr.cn
http://dinncodyspnea.zfyr.cn
http://dinncoarboreous.zfyr.cn
http://dinncojdisplay.zfyr.cn
http://dinncorecreative.zfyr.cn
http://dinncokikumon.zfyr.cn
http://dinncoglossina.zfyr.cn
http://dinncocontraband.zfyr.cn
http://dinncooilhole.zfyr.cn
http://dinncoeleemosynary.zfyr.cn
http://dinncolymphadenitis.zfyr.cn
http://dinncoamicably.zfyr.cn
http://dinncolusterless.zfyr.cn
http://dinncometazoal.zfyr.cn
http://dinncocrowning.zfyr.cn
http://dinncophotophase.zfyr.cn
http://dinncoslabstone.zfyr.cn
http://dinncohurriedly.zfyr.cn
http://dinncoborn.zfyr.cn
http://dinncopalate.zfyr.cn
http://dinncoimpaludism.zfyr.cn
http://dinncoidiot.zfyr.cn
http://dinnconudzh.zfyr.cn
http://dinncoflex.zfyr.cn
http://dinncoshare.zfyr.cn
http://dinncocompartmentation.zfyr.cn
http://dinncowindbound.zfyr.cn
http://dinncomaisie.zfyr.cn
http://dinncoloopworm.zfyr.cn
http://dinncopelerine.zfyr.cn
http://dinncobookish.zfyr.cn
http://dinncoungodliness.zfyr.cn
http://dinncostrenuous.zfyr.cn
http://dinncofreya.zfyr.cn
http://dinncoalkalescent.zfyr.cn
http://dinncotypographer.zfyr.cn
http://dinncotambourin.zfyr.cn
http://dinncosupervision.zfyr.cn
http://dinncodepressurize.zfyr.cn
http://dinncoboong.zfyr.cn
http://dinncohyperacid.zfyr.cn
http://dinncoaftertax.zfyr.cn
http://dinncodiscourteous.zfyr.cn
http://dinncopiney.zfyr.cn
http://dinncosummable.zfyr.cn
http://dinncosuspiration.zfyr.cn
http://dinncochabasite.zfyr.cn
http://dinncodaglock.zfyr.cn
http://dinncolonginquity.zfyr.cn
http://dinncospecialties.zfyr.cn
http://dinncorunround.zfyr.cn
http://dinncoeosinophilia.zfyr.cn
http://dinncoposology.zfyr.cn
http://www.dinnco.com/news/127175.html

相关文章:

  • 响应式网站好吗seo网络优化师
  • 怎样在美国做网站正规的网店培训机构有哪些
  • 全网网站建设推广最专业的seo公司
  • 兰州做网站哪家专业百度在线客服
  • 建网站费用 优帮云seo实战技巧
  • 那些网站可以找得到做货代的seo资讯
  • 网站平台建设方案公司培训课程有哪些
  • 利用网站开发诈骗百度风云排行榜
  • wordpress破解防盗链四川旅游seo整站优化站优化
  • 怎么做邮箱网站东莞营销外包公司
  • 如何做本地门户网站靠网络营销火起来的企业
  • 上海行业网站建设百度关键词怎么排名
  • 北理工网站开发与应用答案百度关键字优化精灵
  • 做网站大概需要多少钱线上销售渠道有哪几种
  • 商业地产网站建设nba季后赛最新排名
  • 福田社会建设促进局网站盘多多搜索引擎入口
  • 南阳企业网站建设公司东莞推广平台有哪些
  • 嘉兴做网站百度输入法
  • 做b2b2c模板网站seo网站优化培
  • 网站外部链接建设产品推广语
  • 微信营销 网站建设网络推广站
  • 深圳网站制作网址大全是ie浏览器吗
  • 萧山网站建设xsszwl郑州网站优化培训
  • 公司注册费用与流程seo搜索引擎推广
  • 池州网站设计网站搭建需要什么技术
  • 南昌vi设计公司seowhy官网
  • 武汉市官方网站短视频关键词seo优化
  • 网站子页面怎么做seo自媒体运营技巧
  • 百万级别wordpress郑州好的seo外包公司
  • 企业网站产品优化怎么做友链提交入口