码迷,mamicode.com
首页 > 其他好文 > 详细

STL源码剖析 学习笔记

时间:2017-07-27 11:35:16      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:ack   fine   工具   ati   内存分配   red   ide   序列   rem   

目录:

  第二章  空间适配器

  第三章  迭代器

  第四章  序列式容器(vector,list,deque,stack,heap,priority_queue,slist)

  第五章  关联式容器(树的算法 + RB_tree ,set,map,hashtable)

  第六章  算法

  第七章  仿函数

  第八章  适配器(adapet)

 

第二章  空间适配器

  具有次配置力的SGI空间适配器,STL allocator将对象的内存分配和初始化分离开,内存配置由alloc:allocate 负责,内存释放由deallocate 负责,对象构造操作 由 construct() 负责,对象析构操作由destroy() 负责。

  构造和析构的基本工具:construct 和destory

  (trival constructor :: 

59down voteaccepted

In simple words a "trivial" special member function literally means a member function that does its job in a very straightforward manner. The "straightforward manner" means different thing for different kinds of special member functions.

For a default constructor and destructor being "trivial" means literally "do nothing at all". For copy-constructor and copy-assignment operator, being "trivial" means literally "be equivalent to simple raw memory copying" (like copy with memcpy).

If you define a constructor yourself, it is considered non-trivial, even if it doesn‘t do anything, so a trivial constructor must be implicitly defined by the compiler.

In order for a special member function to satisfy the above requirements, the class must have a very simplistic structure, it must not require any hidden initializations when an object is being created or destroyed, or any hidden additional internal manipulations when it is being copied.

For example, if class has virtual functions, it will require some extra hidden initializations when objects of this class are being created (initialize virtual method table and such), so the constructor for this class will not qualify as trivial.

For another example, if a class has virtual base classes, then each object of this class might contain hidden pointers that point to other parts of the very same object. Such a self-referential object cannot be copied by a simple raw memory copy routine (like memcpy). Extra manipulations will be necessary to properly re-initialize the hidden pointers in the copy. For this reason the copy constructor and copy-assignment operator for this class will not qualify as trivial.

For obvious reasons, this requirement is recursive: all subobjects of the class (bases and non-static members) must also have trivial constructors.

    

STL源码剖析 学习笔记

标签:ack   fine   工具   ati   内存分配   red   ide   序列   rem   

原文地址:http://www.cnblogs.com/joeylee97/p/7243633.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!