Skip to content

Commit 94c4ac4

Browse files
committed
add stl list comments
1 parent 3da6ca8 commit 94c4ac4

File tree

9 files changed

+1288
-1660
lines changed

9 files changed

+1288
-1660
lines changed

2_STL_allocator/2_2_4_stl_alloc.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,10 @@ class __default_alloc_template {
344344
return (((bytes) + __ALIGN-1) & ~(__ALIGN - 1));
345345
}
346346
__PRIVATE:
347-
union obj { // free-lists 的节点构造
348-
union obj * free_list_link;
349-
char client_data[1]; /* The client sees this. */
347+
// free-lists 的节点构造,用 union,节约空间,不需要额外保存一个指向下一个节点的指针
348+
union obj {
349+
union obj * free_list_link; // 作为空闲链表上的节点时,指向下一个空闲节点
350+
char client_data[1]; // 分配给用户之后,表现为一个区块的起始位置,即一块分配给用户的空间
350351
};
351352
private:
352353
# ifdef __SUNPRO_CC

2_STL_allocator/2_3_1_stl_uninitialized.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,9 @@ inline ForwardIterator __uninitialized_fill_n(ForwardIterator first, Size n,
224224
template <class ForwardIterator, class Size, class T>
225225
inline ForwardIterator uninitialized_fill_n(ForwardIterator first, Size n,
226226
const T& x) {
227+
// value_type() 可以很方便地获取迭代器的类型
227228
return __uninitialized_fill_n(first, n, x, value_type(first));
228-
// 以上,利用 value_type() 取出 first 的 value type
229+
// 以上,利用 value_type() 取出 first 的 value type,该函数见 3_6_stl_iterator.h
229230
}
230231

231232
// Copies [first1, last1) into [result, result + (last1 - first1)), and

0 commit comments

Comments
 (0)