Strong Guarantee using Transaction
Posted on April 29th, 2008 at 23:24 by fr3@K

Abrahams Guarantees

在 C++ 的世界裡, 正確的 exception handling 是專業的 C++ programmer 不可或缺的技巧. 雖然它的概念並不困難, 但實作起來卻常不見得那麼容易.

要做到正確的 exception handling, 首先必須要了解什麼是 exception safety. 一個需要與 exception 打交道的 component 可在其介面實作人稱 Abrahams guarantees 的三種 exception safety 保證之一:

  1. The basic guarantee
  2. 允許操作失敗時改變物件的狀態, 但不能有 resource leak. 且該物件的狀態必須是可靠的仍然可以被解構, 操作失敗後該物件的狀態可以是不完全能被預測的.

  3. The strong guarantee
  4. 操作後的狀態只能是成功完成, 或是將該物件回復到操作之前的狀態並拋出一個 exception.

  5. The no-throw guarantee
  6. 操作不會拋出 exception.

(more…)

del.icio.us:Strong Guarantee using Transaction digg:Strong Guarantee using Transaction spurl:Strong Guarantee using Transaction newsvine:Strong Guarantee using Transaction furl:Strong Guarantee using Transaction Y!:Strong Guarantee using Transaction 黑米共享書籤:Strong Guarantee using Transaction 推推王:Strong Guarantee using Transaction
re: Socket Programming in C 常犯的錯誤
Posted on April 22nd, 2008 at 12:25 by fr3@K

昨天在網上閒逛, 在樂多上看到篇名為 “Socket Programming in C 常犯的錯誤” 的短文. 這短文作者的動機很好, 指出常見到的錯誤並提供個人看法與可能較好的作法. 這樣的行為很值得鼓勵. 但極可惜的是, 結果卻是很不理想的. 容我說句重話, 如果是考試的話該文是得不到我的分數的.
(more…)

del.icio.us:re: Socket Programming in C 常犯的錯誤 digg:re: Socket Programming in C 常犯的錯誤 spurl:re: Socket Programming in C 常犯的錯誤 newsvine:re: Socket Programming in C 常犯的錯誤 furl:re: Socket Programming in C 常犯的錯誤 Y!:re: Socket Programming in C 常犯的錯誤 黑米共享書籤:re: Socket Programming in C 常犯的錯誤 推推王:re: Socket Programming in C 常犯的錯誤
五種寫 For Loop 的方法
Posted on April 11th, 2008 at 6:23 by fr3@K

同樣是寫一個迭代的 loop, 至少有下面兩種標準 (C++98), 兩種半標準 (Boost), 以及一種未來式 (C++0x) 的寫法:
(more…)

del.icio.us:五種寫 For Loop 的方法 digg:五種寫 For Loop 的方法 spurl:五種寫 For Loop 的方法 newsvine:五種寫 For Loop 的方法 furl:五種寫 For Loop 的方法 Y!:五種寫 For Loop 的方法 黑米共享書籤:五種寫 For Loop 的方法 推推王:五種寫 For Loop 的方法
Source Code [Benchmarking Sequential Iterators]
Posted on March 17th, 2008 at 23:39 by fr3@K

Source code used to produce results in my previous post is available for download here.

Please note that Boost.Date_Time is required in order to build it.

del.icio.us:Source Code [Benchmarking Sequential Iterators] digg:Source Code [Benchmarking Sequential Iterators] spurl:Source Code [Benchmarking Sequential Iterators] newsvine:Source Code [Benchmarking Sequential Iterators] furl:Source Code [Benchmarking Sequential Iterators] Y!:Source Code [Benchmarking Sequential Iterators] 黑米共享書籤:Source Code [Benchmarking Sequential Iterators] 推推王:Source Code [Benchmarking Sequential Iterators]
NULL 指標兩三事
Posted on September 16th, 2007 at 21:51 by fr3@K

最近被我面試的十來位應徵者, 除了一位之外, 都不清楚以下兩個 pointer to NULL (指向 0 的指標) 的基本特性:

  • delete 一個指向 NULL 的指標是安全的
  • 以一個指向 NULL 的 C-style 字串為參數呼叫 strlen 會造成死機 (segmentation fault, access violation or whatever)

(more…)

del.icio.us:NULL 指標兩三事 digg:NULL 指標兩三事 spurl:NULL 指標兩三事 newsvine:NULL 指標兩三事 furl:NULL 指標兩三事 Y!:NULL 指標兩三事 黑米共享書籤:NULL 指標兩三事 推推王:NULL 指標兩三事
WP-Notable - Patched to Support funP and HEMiDEMi
Posted on September 12th, 2007 at 20:39 by fr3@K

記不清楚 WP-Notable 這個 plugin 已經用了多久. 也不知道到底有多少瀏覽 COdE fr3@K 的人用過它 (我甚至還懷疑到底有沒有人用過它). 說穿了, 安裝它的原因也不過就是小小的虛榮心作祟. 讓 COdE fr3@K 看起來能跟所謂的 Web 2.0 沾上點邊, (即便 COdE fr3@K 的內容一點也不 Web 2.0) 也製造跟重要的網站有連結的假象.
(more…)

del.icio.us:WP-Notable - Patched to Support funP and HEMiDEMi digg:WP-Notable - Patched to Support funP and HEMiDEMi spurl:WP-Notable - Patched to Support funP and HEMiDEMi newsvine:WP-Notable - Patched to Support funP and HEMiDEMi furl:WP-Notable - Patched to Support funP and HEMiDEMi Y!:WP-Notable - Patched to Support funP and HEMiDEMi 黑米共享書籤:WP-Notable - Patched to Support funP and HEMiDEMi 推推王:WP-Notable - Patched to Support funP and HEMiDEMi
Resource Management using auto_ptr - Not Always So Simple
Posted on September 6th, 2007 at 23:03 by fr3@K

接續兩個多禮拜前, 那篇 囉唆的開場

話說那天面試 A 君作答最後一題的過程中, 或許是 A 君作答的速度慢了. 突然想到自己沒有用過真實世界的例子仔細檢驗過我所謂好方法. 面試後想像了幾個狀況, 我的 C++ 世界開始出現烏雲…
(more…)

del.icio.us:Resource Management using auto_ptr - Not Always So Simple digg:Resource Management using auto_ptr - Not Always So Simple spurl:Resource Management using auto_ptr - Not Always So Simple newsvine:Resource Management using auto_ptr - Not Always So Simple furl:Resource Management using auto_ptr - Not Always So Simple Y!:Resource Management using auto_ptr - Not Always So Simple 黑米共享書籤:Resource Management using auto_ptr - Not Always So Simple 推推王:Resource Management using auto_ptr - Not Always So Simple
Resource Management using auto_ptr - Intro
Posted on August 19th, 2007 at 2:14 by fr3@K

周五下午在新上任的工作進行了第一次面試. 被面試的這位應徵者 (就稱為 A 君吧) 已有三年以上在工作上使用 C++ 的經驗, 對自己的 C++ 能力的評比給的是熟悉 (還沒到精通) . 在聊了可能一個鐘頭左右後, 他表示自己寫程式很少發生 memory leak, 卻又舉例不出具體作法, 只表示這是經驗與習慣使然. 針對這點, 我在白板上出了個題目:

    class foo {};
    class bar
    {
      foo* fp_;
    public:
      bar(foo* fp)
      : fp_(fp)
      {
        // ....
      }
      ~bar()
      {
        delete fp_;
      }
    };
    
    bar* create_bar()
    {
      foo* fp = new foo;
      return new bar(fp);
    }
    

    假設你是負責維護 create_bar 的 programmer. 並且, 呼叫 create_bar 的使用者一定會記得 delete 掉被該 function new 出來的 instance . 請問 create_bar 這個函數有沒有潛在的 leak? 如果有, 可以如何改善?

(more…)

del.icio.us:Resource Management using auto_ptr - Intro digg:Resource Management using auto_ptr - Intro spurl:Resource Management using auto_ptr - Intro newsvine:Resource Management using auto_ptr - Intro furl:Resource Management using auto_ptr - Intro Y!:Resource Management using auto_ptr - Intro 黑米共享書籤:Resource Management using auto_ptr - Intro 推推王:Resource Management using auto_ptr - Intro
ERROR_SUCCESS
Posted on June 14th, 2007 at 23:35 by fr3@K

哈哈哈~~ 要不是看到 Checko這篇, 都已經忘記 ERROR_SUCCESS 這回事了.

搞不清楚當初制定的人到底是:

  • 不知變通, 傳回值一定要以 ERROR 當 prefix
  • 英文 and/or 邏輯不好, 不知道這其實是不通的
  • 腦殘
  • 以上皆是
del.icio.us:ERROR_SUCCESS digg:ERROR_SUCCESS spurl:ERROR_SUCCESS newsvine:ERROR_SUCCESS furl:ERROR_SUCCESS Y!:ERROR_SUCCESS 黑米共享書籤:ERROR_SUCCESS 推推王:ERROR_SUCCESS
給留言朋友的 Mini HTML 教學與建議
Posted on May 27th, 2007 at 1:47 by fr3@K

最近一些朋友在我這邊留言, 貼出來的結果常常不如預期. 我也是過來人, 很清楚他們雖然都是 programmer, 但其實對 HTML 並不熟悉. 就跟我一開始寫這個 blog 的時候一樣. 現在的我當然比以前好多了, 勉強還有一兩樣東西可以拿出來與其他人分享.
(more…)

del.icio.us:給留言朋友的 Mini HTML 教學與建議 digg:給留言朋友的 Mini HTML 教學與建議 spurl:給留言朋友的 Mini HTML 教學與建議 newsvine:給留言朋友的 Mini HTML 教學與建議 furl:給留言朋友的 Mini HTML 教學與建議 Y!:給留言朋友的 Mini HTML 教學與建議 黑米共享書籤:給留言朋友的 Mini HTML 教學與建議 推推王:給留言朋友的 Mini HTML 教學與建議

Page 1 of 2[ 1 ]2»