原创 使用gdb調試nginx源碼

工欲善其事必先利其器,如何使用調試工具gdb一步步調試nginx是瞭解nginx的重要手段。 ps:本文的目標人羣是像我這樣初接觸Unix編程的同學,如果有什麼地方錯誤請指正。 熟悉gdb的使用 這裏就不說了,谷歌一搜一堆,這裏推

原创 muduo源碼分析:線程特定/私有數據類ThreadLocal

線程私有數據 1.__thread : gcc內置的線程局部存儲設施 __thread只能修飾POD類型 POD類型(plain old data),與C兼容的原始數據,例如,結構和整型等C語言中的類型是 POD 類型,但帶有用戶定義

原创 leetcode:word break II

Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid di

原创 leetcode:Word Break

Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of o

原创 leetcode:Single Number

轉自:http://www.acmerblog.com/leetcode-solution-single-number-ii-6317.html Single Number Given an array of integers,

原创 SQL優化

網上關於SQL優化的教程很多,但是比較雜亂。近日有空整理了一下,寫出來跟大家分享一下,其中有錯誤和不足的地方,還請大家糾正補充。 這篇文章我花費了大量的時間查找資料、修改、排版,希望大家閱讀之後,感覺好的話推薦給更多的人,讓更多的人看

原创 auto_ptr、shared_ptr、weak_ptr、scoped_ptr用法小結

auto_ptr   auto_ptr是現在標準庫裏面一個輕量級的智能指針的實現,存在於頭文件 memory中,之所以說它是輕量級,是因爲它只有一個成員變量(擁有對象的指針),相關的調用開銷也非常小。   下面的代碼來自於VC++

原创 leetcode 146. LRU Cache

Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations

原创 git/github初級運用自如

轉自:蟲師 http://www.cnblogs.com/fnng/archive/2012/01/07/2315685.html 開源電子書-講得很全:http://www.worldhello.net/gotgithub/inde

原创 leetcode 143. Reorder List

Given a singly linked list L: L0→L1→…→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must do this in-place witho

原创 muduo源碼分析:日誌相關類(1)

1.stringPiece 類:當字符串來用 統一 char * 字符串 和 std::string 。通過char *字符串 或者 string作參數 傳遞 字符串 ,形參爲stringPiece類型,就不會有內存拷貝 stringPi

原创 leetcode 142. Linked List Cycle II

Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Note: Do not modify t

原创 muduo源碼分析:線程池類ThreadPool

線程池包括 成員變量: 一個任務隊列:deque queue_,用條件變量同步 線程組:ptr_vector threads_ bool running :標誌是否start啓動了,或者stop 停止了 成員函數: start:初始化線程

原创 muduo源碼分析:無界隊列和有界隊列(消費者-生產者)

muduo庫的隊列很簡單: 無界隊列 put --生產 take--消費 size--返回現在的產品數 產品存放在deque裏面 無界隊列可以一直生產put,所以不用等待隊列中有位置才生產,每生產一個產品就notify,只要通知一個消費者

原创 muduo庫源碼解析:單例模式singleton

單例模式實現 boost::noncopyable 防止複製,如果是自己實現,那要把構造函數、拷貝構造,複製構造都私有 公有方法: 獲取單例對象:instance() 返回 value 引用,(第一次 -->pthread_once --