Timothy

链接

《More Effective C++》------ ( 2 )
《More Effective C++》------ ( 4 )

《More Effective C++》------ ( 3 )

Timothy posted @ 2010年6月08日 05:03 in Reading Notes , 1204 阅读
条款10:在constructor内组织资源泄漏。
 
(1):在constructor内初始化指针成员发生异常时,无法调用到析构,于是此成员无法会泄漏。
 
(2):避免方法,try catch,或者把这样的初始化分散到各个private成员函数中,分开捕获异常;最好的方法,把这样的成员封装成智能指针,自动析构。
 
 
 
条款11:不要让异常流出destructor。
 
(1):避免发生栈辗转机制。
 
栈辗转机制:在执行一个函数,catch到一个异常,正在处理时,又抛出一个异常,且没有捕获,传到了上层这个函数,则会发生terminate。
 
(2):要保证所有需要析构的工作都正常完成。
 
 
 
条款12:理解抛出异常和传递一个参数或者调用一个虚函数之间的区别
 
(1):调用一个函数,控制权回到调用者这里;但是抛出一个异常后,控制权不会再回到抛出地点。
 
(2):异常对象一定是以复制对象传递。
 
 
 
条款13:以引用方式传递对象
 
(1):接收到异常对象时,以写 throw; 再次抛出,而不是 throw expobj; 这样会触发再次复制。
 
 
 
条款14:小心使用异常规格( Exception specifications )
 
(1):函数在抛出一个不符合异常规格的异常时,会触发 Unexpected函数,它的缺省行为是terminate, terminate的缺省行为就是 abort.
 
(2):Exception Specifications不检查嵌套性。
 
 
 
条款15:了解异常机制带来的开销
 
 
 
--------------------------------------------------------------------------------------------------------------------------
 
-------------------------------------------------------------
 
效率Efficiency
 
 
 
条款16:牢记80-20法则
 
 
 
条款17:考虑使用Lazy evaluation( 缓式评估)
 
(1): 4个表现方面: a),引用计数,避免不需要的对象拷贝;b),对字符串的 [] 操作符,在读写时区别对待 c), 延缓读写数据库 d), 延缓计算复杂度表达式值
 
(2); 核心思想: 最 缓 的执行某些消耗较大却非必要马上执行的计算或操作,前期以各种技巧规避之。
 
 
 
条款18:分期摊还期望的计算( over-eager evaluation, 急迫式评估 )
 
(1):核心思想:  你认为某个运算或动作需要频繁的执行,则可以采用数据结构或策略高效的处理,降低每次计算的开销。
 
(2):两个例子: cache( 缓存 ) 和  prefeching( 提前读取,预先申请空间)
 
 
 
条款19:理解临时对象的来源
(1):一般有两个主要方式, 为了使函数调用成功执行的隐式转换产生对象 和 函数返回一个对象时。
 
条款20:协助完成对函数返回值的优化
(1):返回对象时,切忌不可返回 栈上对象的引用。
(2):返回对象时,先声明对象,再返回,必将触发复制构造和析构,就是临时对象效率问题,可以 constructor argument
    即  return CA( ... );  //返回一个CA对象 
    原理是: C++允许优化不出现的临时对象(此种返回,对象没有具名实际出现过) --- 返回值优化
 

 

 

Avatar_small
Punjab Plus One Prev 说:
2022年8月24日 21:52

The Punjab Board Class 11th Important Model Question Paper 2023 would be helpful to those who desire to succeed in the Class 11 Punjab Board Exam. Due to a more precise indication of the assignments and tests they will be expected to complete during the academic year, students will be better equipped to handle the Punjab Board 11th Grade. <a href="https://www.modelpaper2020.in/punjab-1-model-paper-202/">Punjab Plus One Previous Paper 2023</a> It will be important for students to participate in its creation, and a well-designed Subjects Wise Important Model Question Paper 2023 will work to make it as interactive as possible by including students in the process of making it.

Avatar_small
AP SSC fa 4 Model Pa 说:
2022年9月09日 01:52

Formative Assessment means not only an examination, it includes various aspects such as Examination in completed lessons, Reflections, Project work done on the allotted topic and Self also Prepared notes etc. AP SSC fa 4 Model Paper Candidates of Telugu Medium, English Medium & Urdu Medium of the AP State can download the AP 10th Class FA 4 Model Paper 2023 Pdf with answers for the regular exams conducted by the Directorate of Government Examinations, Andhra Pradesh.

Avatar_small
chatgpt dokument hoc 说:
2023年7月26日 00:21

ChatGPT kann viel mehr als nur Inhalte produzieren; Es kann auch bei der Prüfung, Überprüfung, Ergänzung und Recherche von Texten und Daten hilfreich sein. Obwohl Word-Dokumente noch nicht auf ChatGPT hochgeladen wurden, chatgpt dokument hochladen kann das Ghostwriter-Add-in ChatGPT-Funktionen in Word bereitstellen. Sie können auch Dateien und Dokumente in Google Docs hochladen, die KI von Google Labs nutzen, Ihr Dokument in PDF umwandeln und es dann in Bing Chat oder ChatPDF hochladen.

Avatar_small
PSEB 8th Class Syll 说:
2023年8月03日 18:47

PSEB 8th Class Exam Date Sheet 2024 Available at Official Website, Every Year This Elementary School Final Exam Conducted Month of April, so Students Download Punjabi Class new Syllabus 2024 Regular Redding and Fallow for Final Exam Better Performance,Students we are Providing here the Latest Updated PSEB Class Syllabus 2024, Punjab Board Students who entered 8th Class This year PSEB 8th Class Syllabus 2024 must go Through This Latest Syllabus to Understand the course Structure for the Upcoming Part of the Current Academic Session.one of the most Important Tools that help in knowing the Course Description.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter