Two points - STL, and multi-threading

来源:互联网 发布:陈鸿一鸣 知乎 编辑:程序博客网 时间:2024/05/01 13:31

* About STL : never trust its performance too much

STL is a standard now. You cannot avoid it ever. People trust it a lot, but keep it in mind: STL is not as good as you think of it. First, you have to know its internal implementation, or you'll make mistakes. As std::map, you can never change its key value because it takes a binary tree as its cardinal structure. Second, it's performance is not that good. Well, this is the issue by design. STL focuses on general issues, so if you have strict perf. constraints in your app, you'd better write your own stuff.

* Multi-threading : sometimes ostrich algorithm is the best solution

If you've got a damn shared data under a multi-threading environment, you may be troubled by it if you have little multi-threading dev. experience. Maybe your first idea is to add locks to the shared data or sth else. But not so long you will be confused by the complex logics of your code. Maybe you'll harvest dead lock, maybe the data is still shared orderlessly. When you got tired, you must be complaining that why there's such shared data?! Yes, the answer is your complaint words: Just remove the shared data~! It's ostrich algorithm, it's too simple to make it an algorithm, but it works. What's the most important: it can save your time a lot~!

原创粉丝点击