2012年12月1日 星期六

[C++] A *a 和 A *aa = new A 的差別

在寫C++過程中,指標的使用與操作是最頻繁被使用的,有些難解的bug,通常point佔絕大多數,這裡複習一個很基本的概念。

如下面的例子,個別使用兩個a指標,也各自呼叫他們的member function test(),發覺都可以印出test的字串,但為什麼第一個指標明明是指向undefine的空間,為什麼不會出現問題呢,不是應該要出現Segmentation Fault嗎?

這裡隱藏一個很重要,也很容易被誤解的觀念,通常使用null point或不知指向何處的point時,操作member function是不會發生Segmentation Fault的,會產生Segmentation Fault是在操作它的member時,如果下面的程式碼多加上一段a->value的話,當程式運行到這一行就會發生crash了。

2012年11月11日 星期日

[Aadroid] Android版本控制工具---Repo(轉)

Android 原始碼下載及版本控制 - 使用git與repo

要取得Android的原始碼,會需要用到Git和Repo還有Gerrit。 以下解釋一些工具,太冗長,可直接拉到最下方看如何取得Android原始碼。

什麼是Git?

Git is an open-source version-control system designed to handle very large projects that are distributed over multiple repositories.

那Git for Android是?

In the context of Android, we use Git for local operations such as local branching, commits, diffs, and edits. One of the challenges in setting up the Android project was figuring out how to best support the outside community–from the hobbiest community to large OEMs building mass-market consumer devices. We wanted components to be replaceable, and we wanted interesting components to be able to grow a life of their own outside of Android. We first chose a distributed revision control system, then further narrowed it down to Git.

2012年11月1日 星期四

[Tool] Source Insight常用的快捷鍵

@Source Insight常用的快捷鍵:

  • Ctrl+= :Jump to definition
  • Alt+/ :Look up reference
  • Alt+分頁標題首字字母 : 切換至該標題的頁面
  • F3 : search backward
  • F4 : search forward
  • F5: go to Line
  • F7 :Look up symbols
  • F8 :Look up local symbols
  • F9 :Ident left
  • F10 :Ident right
  • Alt+, :Jump backword
  • Alt+. : Jump forward
  • Shift+F3 : search the word under cusor backward
  • Shift+F4 : search the word under cusor forward
  • F12 : incremental search
  • Shift+Ctrl+f: search in project
  • shift+F8 : hilight word

2012年10月27日 星期六

[Vim]常用的技巧記錄

@VIM外掛安裝方式

透過github
(1)使用git submodule add  "要安裝plugin的路徑"   bundle/plugin-name
frank@frank:~/.vim$ git submodule add https://github.com/vim-scripts/taglist.vim.git bundle/Taglist  ./bundle/Taglist

(2)輸入指令初始化外掛
frank@frank:~/.vim$ git submodule init

2012年10月13日 星期六

[C++]必須傳回物件時,別妄想傳回其reference

函數的回傳值使用上要非常的小心,雖然程式寫久了,這算是比較基礎的概念,但有時一疏忽,往往就會造成系統Crash,簡單來說,函式產生新物件的路徑有二,在Stack空間或是在Heap空間裡,以底下例子來說。

const Rational& operator* (const Rational& lhs,
                                        const Rational& lhs)
{
    Rational result(lhs.n * rhs.n, lhs.d* rhs.d)
    return result;
}

2012年9月21日 星期五

[C++]寧以pass-by-reference-to-const取代pass-by-value

在C++裡函式參數使用pass-by-value的話,會造成參數的傳遞成本增加,所以在C++應用程式或是component開發上比較少使用pass-by-value。

在Google C++ Style Guide裡有提到Google內部使用C++ coding的規則,從裡面也可以看到Google的rule為所有函式的參數必須是pass-by-reference,並且加上cosnt,表示傳入的參數是不可以變動的,這時你可能會有個疑問,如果函式的實作需要修改到傳入的參數怎麼辦,當然這應該是很常見的case,所以他們對於有需要更改操作的arguments,可以使用pass-by-point的方式。

2012年9月15日 星期六

[Android] 常用的adb指令


身處在開發Android的公司,adb指令可以說是跟mobile device有非常密切的關係,舉凡push, pull data到devices上,甚至debug除錯等,都會需要使用到adb工具,所以了解並熟悉adb的一些指令對於開發上具有非常大之幫助。


◎這裡列出官網上提到,以及比較常使用到的指令

1.adb devices (顯示目前有多少個模擬器正在執行) 

2.adb -s (指定模擬器來操作)  
    Ex:adb -s emulator-5554 install camera.apk