research of list-new

research of list-new

ID:21248068

大小:2.89 MB

页数:43页

时间:2018-10-20

research of list-new_第1页
research of list-new_第2页
research of list-new_第3页
research of list-new_第4页
research of list-new_第5页
资源描述:

《research of list-new》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、STLresearch–list SGI2.91Briefintroductionoflistmemoryallocate–allocatorTheinterfacesofallocatorTwotypesofallocatorsDatastructureoflist–BidirectionalcircularlinkedlistAlgorithmsandmembermethodsoflistBriefintroductionoflistlistisakindofsequencecontainer.Itisbidirectionalci

2、rcularlinkedlist,whichcanstoretheelementslocatedindiscontinuousstoragelocations.Advantages:Constanttimetoinsertordeleteanelementanywhereinthecontainer.Providingmoreefficientmemberfunctionthancommonalgorithmswithsamename,suchasremove()andunique().Theiteratorsoflistwillnot

3、beinvalidafterinsertionorremovalexcepttheonejustdeleted.Disadvantages:Lackdirectaccesstotheelementbyitsposition.memoryallocate-allocatorTheSTLcontainershavethefeatureofchangingtheirsizesduringtheruntime.Toachievethis,someformofdynamicmemoryallocationisrequired.Theimporta

4、ntinterfacesofalloctor:templateclassallocator{_Tp*allocate(size_type__n,constvoid*=0){return__n!=0?static_cast<_Tp*>(_Alloc::allocate(__n*sizeof(_Tp))):0;}voiddeallocate(pointer__p,size_type__n){_Alloc::deallocate(__p,__n*sizeof(_Tp));}voidconstruct(pointer__p,

5、const_Tp&__val){new(__p)_Tp(__val);}voiddestroy(pointer__p){__p->~_Tp();}}TwotypeofallocatorsTherearetwotypesofdefaultallocatorsusedbySTL:Firstlevelallocator:Handlethememoryrequestedthatismorethan128bytes.Secondlevelallocator:Handlethememoryrequestedwhichislessthan128byt

6、es.It’sdesignedtoavoidmemoryfragmentation.STLusesthesecondlevelallocatorindefaultunlessthememoryrequestedismorethan128bytes.Ifthemacroname“__USE_MALLOC”isdefined,itwillcallthefirstlevelallocator.memoryallocate–allocatorThefirstlevelallocatorThesecondlevelallocatorNexttem

7、plateclass__malloc_alloc_template{private://oom:outofmemorystaticvoid*_S_oom_malloc(size_t);staticvoid*_S_oom_realloc(void*,size_t);staticvoid(*__malloc_alloc_oom_handler)();public:staticvoid*allocate(size_t__n){void*__result=malloc(__n);if(0==__result)__resul

8、t=_S_oom_malloc(__n);return__result;}staticvoiddeallocate(void*__p,size_t/*__n*/){free(__p);}staticvoid

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。