![](https://img-blog.csdnimg.cn/91fab64aaf9d4934946b7b1f75b5e539.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
stl源代码分析
stl源代码分析
thefist11
难以忘记编程路上领导和好友的细致指导,所以必须努力!(真诚希望大家多多指导!)
展开
-
STL源代码分析(ch 1)组态1
1. __STL_STATIC_TEMPLATE_MEMBER_BUGstatic member of template classes(模板类静态成员)template <typename T>class test{public: static int _data;}int test<int>::_data=1;int test<char>::_data=2;2. __STL_CLASS_PARTIAL_SPECIALIZATION模板类偏特化,原创 2022-03-21 23:36:31 · 183 阅读 · 0 评论 -
STL源代码分析(ch 1)概述
1. 6大组件容器(containers):各种数据结构,如vector、list、deque、set、map,用来存放数据。从实现来看,STL容器是一种 class template。算法(algorithms):各种常用算法如 sort、search、copy、erase,从实现的角度来看,STL算法是一种 function template。迭代器(iterators):扮演容器与算法之间的胶合剂,是所谓的“泛型指针”,共有五种类型,以及其它衍生变化,从实现的角度来看,迭代器是一种将:opera原创 2022-03-19 09:12:04 · 269 阅读 · 0 评论 -
STL源代码分析(ch2 内存分配)概述
1. 使用场景2. 配置器定义在头文件中//负责内存空间的配置与释放;<stl_alloc.h>//文件中定义了一、二两级配置器,彼此合作,配置器名为alloc。//负责对象内容的配置与释放<stl_construct.h>//全局函数construct()和destroy(),负责对象的构造和析构。//用来填充fill或复制copy大块内存数据<stl_uninitialized.h>//uninitialized_copy();uninitialize原创 2022-03-25 08:24:30 · 91 阅读 · 0 评论 -
STL源代码分析(ch2 内存分配)标准接口
标准接口// 以下几种自定义类型是一种type_traits技巧allocator::value_typeallocator::pointerallocator::const_pointerallocator::referenceallocator::const_referenceallocator::size_typeallocator::differenceallocator::rebind1.1 函数allocator::allocator() // 默认构造函数allo.原创 2022-03-25 09:34:12 · 99 阅读 · 0 评论 -
STL源代码分析(ch2 内存分配)uninitialized_fill_n
1. uninitialized_fill_n(ForwardIter first, Size n, const T& value)从 first 位置开始,填充 n 个元素值,返回填充结束的位置template <class ForwardIter, class Size, class T>ForwardIter uninitialized_fill_n(ForwardIter first, Size n, const T& value){ return mystl原创 2022-03-30 19:37:22 · 450 阅读 · 0 评论 -
STL源代码分析(ch2 内存分配)uninitialized_fill
1. uninitialized_fill(ForwardIter first, ForwardIter last, const T& value)// uninitialized_fill// 在 [first, last) 区间内填充元素值template <class ForwardIter, class T>void uninitialized_fill(ForwardIter first, ForwardIter last, const T& value)原创 2022-04-02 06:55:04 · 134 阅读 · 0 评论 -
STL源代码分析(ch2 内存分配)jjalloc.h
1. jjalloc.h#ifndef _JJALLOC_#define _JJALLOC_#include<new>//for placement new#include<cstdlib>//for ptrdiff_t,size_t#include<climits>//for UINT_MAX#include<iostream>//for cerr namespace JJ { template<class T> i原创 2022-03-25 10:30:21 · 207 阅读 · 0 评论 -
STL源代码分析(ch2 内存分配)uninitialized_fill
1.// uninitialized_fill// 在 [first, last) 区间内填充元素值template <class ForwardIter, class T>void uninitialized_fill(ForwardIter first, ForwardIter last, const T& value){ mystl::unchecked_uninit_fill(first, last, value,原创 2022-03-30 00:53:47 · 368 阅读 · 0 评论 -
STL源代码分析(ch 1)组态2
4. __STL_MEMBER_TEMPLATES模板类中包含模板成员,是否支持template members of classesclass vec {public: typedef T value_type; typedef value_type* iterator; template<class I> void insert(iterator position, I first, I last) { cout << "insert()" <<原创 2022-03-25 08:13:45 · 286 阅读 · 0 评论 -
STL源代码分析(ch2 内存分配)destroy
1. 两个版本1.1 参数是指针template inline void destroy(T* pointer) {pointer->~T(); // 调用析构函数}1.2. 参数接受两个迭代器接受两个迭代器。它会设法找出元素的数值型別,进而利用 __type_traits<> 求取最适当措施。template <class ForwardIterator>inline void destroy(ForwardIterator first, ForwardIt原创 2022-03-26 13:29:39 · 165 阅读 · 0 评论 -
STL源代码分析(ch2 内存分配)分配策略
1. 二级分配双层配置器,第一层直接调用malloc()和free().配置内存小于128bytes时,使用第二级配置器:第二级配置器将小于128bytes的区块使用内存池(memory pool)管理【又称层次配置(sub-allocation)】,即每次配置一大块内存,并维护对应的自由链表(free-list),当下次有相同的内存需求就从free-list拨出,释放小区块就回收至free-list使用16个自由链表负责16种小型区块的次级配置能力。如果内存不足转一级配置器。8 16 24 32原创 2022-03-26 13:33:13 · 202 阅读 · 0 评论