Skip to content

Commit

Permalink
STL与泛型编程
Browse files Browse the repository at this point in the history
  • Loading branch information
ZachL1 committed Feb 9, 2022
1 parent 2ae4443 commit dab2333
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Note/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@



### [基于对象 - 单一的 class](./基于对象%20-%20单一的%20class.md)
## 面向对象高级编程

### [面向对象 - class 与 class 之间的关系](./面向对象 - class 与 class 之间的关系.md)
#### [基于对象 - 单一的 class](./基于对象%20-%20单一的%20class.md)

#### [面向对象 - class 与 class 之间的关系](./面向对象%20-%20class%20与%20class%20之间的关系.md)



## C++ 标准库 体系结构与内核分析

不同于 c 标准库中各个单一的函数,C++标准库主要分为 6 个部件,每一部分都紧密的联系,构成体系结构。

#### part1 STL 与泛型编程



Expand Down
46 changes: 46 additions & 0 deletions Note/STL 与泛型编程.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# STL 与泛型编程

> STL 就是泛型编程的最好示例。
通过泛型编程使用 C++ 标准库的 6 大部件。

6 大部件 (Components) :

- 容器 Containers
- 分配器 Allocators :容器通常都有默认的分配器,因此不需要使用者操心。
- 算法 Algorithms
- 迭代器 Iterators
- 适配器 Adapters
- 仿函数 Functors

![image-20220209155637692](images/image-20220209155637692.png)

### 容器 - 结构与分类

- 顺序容器:数组或链表实现
- 关联容器
- 有序:红黑树实现
- 无序:哈希表实现(一组桶) *C++11*

![image-20220209162214117](images/image-20220209162214117.png)

> 红框标注的为 C++11 新增容器,其中 array 是将原本的语言特显变为 array class
>
> vector 的扩充通过“分配器”实现,分配器完成底层的内存分配工作
##### vector 对象是如何增长的

TODO

> 参看 *《C++ Primer》* p317
##### deque 对象是如何增长的

deque 对象中其实是一连串的指针,每一个指针指向一个 buffer 。buffer 具有固定的长度,能容纳 n 个元素,当 deque 向前或向后增长时首先填充 buffer 内空闲的内存,当 buffer 满了之后再分配新的 buffer。

![image-20220209174417698](images/image-20220209174417698.png)

> **stack 和 queue 实际上是 deque 容器的适配器**,底层就是一个 deque ,各种操作是对 deque 容器的操作的再次封装。
### 源代码之分布

Binary file added Note/images/image-20220209155637692.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Note/images/image-20220209162214117.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Note/images/image-20220209174417698.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit dab2333

Please sign in to comment.