1. Overview
Thread local storage(tls) is a feature provided by most modern operating
systems(OS) that allow multiple threads within a process to have its own “global”
data, but the scope of the “global” data is restricted within a thread
itself, i.e. tls variables are thread wide global variables.
TLS can be useful if we want to store global data which are grouped by
threads, each thread only accesses its own piece of data, and have no loss of
concurrency. Without tls, we would have to store such data in a global data
structure (process wide) and use locks to sychronize access to it.
阅读全文…
各位读者,很抱歉这篇文章是英文的,我当初做笔记的时候,写成英文了,这样才可以在同事之间交流。 而现在确实没时间翻译过来了,还望大家理解,谢谢!
If your code builds well using gcc4.3 and below, it may not build with gcc4.4, which was released in April 2009.
Following are some of the changes that violates c/c++ standard:
1. gcc4.4 does not by default #include stdio.h, or stdlib.h, no header files are by default included, all header files of standard c/c++ libraries need to be explicitly included.
阅读全文…
各位读者,很抱歉这篇文章是英文的,我当初做笔记的时候,写成英文了,这样才可以在同事之间交流。而现在确实没时间翻译过来了,还望大家理解,谢谢!
Following are some corner cases of C++ template features. A lot of the text is simply extracted from “C++ Templates: The Complete Guide”, with some of my personal understanding. These features are trivial and easily neglected, but you should have some impression to them in case you run into troubles caused by the neglect.
I made my notes in English, and I don’t bother to translate them into Chinese, forgive my laziness.
0. use “typename” to extract type defined within a type parameter, like this: typename T::iterator itr; otherwise the ‘itr’ is treated as a data member of T.
1. zero initialization
When using a var x of type T, we MUST initialize it like this: T x = T(); so that when T is a primitive type, x can also be initialized with 0, or NULL (when T is a pointer type). Of course we must make sure
when T is a class type, it has a default constructor. Simply using T x; can’t initialize x when T is a primitive type. 阅读全文…
Sorry the format is poor, I will update it later. Or please see the same article on my blog at baidu which has a better format: http://hi.baidu.com/dazhao_dbblog/blog/item/a1f49efcee4fba1e09244d06.html
C++ template is really a powerful gun in the entire C++ artillery. It is an important part of the defining components that make C++ so powerful, yet so difficult to learn. There are many ways you can make mistakes when using C++, or using C++ templates, just like using any other powerful man-made systems. But if you make everything right, you can gain incredible power, flexibility, efficiency, performance, extendability and so on – anything you dream of in the software engineering world. So it is definitely worthwhile to make the effort to learn C++ well.
In this article I’d like to talk about how to implement the superset of interface mechanism using templates in C++ by using C++ templates, you can do a lot better than ordinary interface mechanism. 阅读全文…
五年多前做了一个DOS下的电子小说阅读器。一晃五年过去了,几乎忘记了它的存在。上周忽然收到广告邮件:“DOS仿真阅读器做的很不错,现在已经有超过9939人下载过它…”,才猛然想起这位失散多年的小兄弟。今天下载人数突破了一万,貌似是个值得纪念的日子。虽然比同类大哥Adobe Reader相比实在是可怜巴巴,不过屈指一算,平均每天有五位素昧平生的用户下载,DOS又式微多年,也算是一个不大不小的意外。
阅读全文…
没有规矩,不成方圆。有时候发现,读好的开源产品的代码,如Linux、JDK等,其感受如饮美酒,喜不自胜。然而最近读到一些国内客户和大学毕业生的代码,其感觉就像一个头有十个大,对比很强烈。
千里之行,始于足下。越是历久弥香的产品,越是要求严格,也就意味着每一行代码都很讲究。要做出世界一流的软件来,除了要遵循软件项目管理的种种规范(需求、设计、风险、测试等等),对于开发者的编码要求和规范也不少。
我想,在此谈谈我的一点浅见。对于一个合格的开发者而言,其编写每一行代码的时候,大致首先要考虑的地方有:
- 我遵循相关的代码规范了没有?
- 注释写了没有?注释写的简洁明了吗?
- 针对各种异常情况加以判断和处理了吗?
- 安全退出了吗?释放内存没?有没有内存泄漏?
阅读全文…
给有志于数据库内核开发的朋友的参考书:
* Stanford大学教授Hector Garcia-Molina同志的书,比如prentice Hall出版的“Database System Implementation”。(Hector Garcia-Molina同志也是Oracle公司顾问团成员之一。)
* 数据库权威Jim Grey的书,比如“Transaction Processing: Concepts and Techniques”。
阅读全文…
Berkeley DB 开源社区的Brett Zamir基于XQuery/BDBXML做了一个Firefox的Add-on, 叫XqUSEme (https://addons.mozilla.org/en-US/firefox/addon/5515)。感兴趣的同学可以下载试试。
Brett Zamir在创建XqUSEme初期与Berkeley DB开发工程师的讨论在: http://forums.oracle.com/forums/thread.jspa?messageID=2239564。
有心的朋友,不知道有考虑过智能手机+浏览器+BDBXML的组合吗?欢迎和我讨论。
在Windows脚本里面创建空白文本文件真是困难重重。采用 echo >tmp.txt是不行的,因为echo会可耻地输出”echo on”。再试试”echo off”+”echo on”的组合拳?依然毫无效果。猛然惊觉系统还有闲置的一条康庄大道stderr,使用之:
echo 2> tmp.txt
stderr没有任何输出,自然产生一个空白文本文件。整个世界清静了…
最近评论