2010年8月31日 星期二

Tuning Applications

1. The Instruments Application
The Instruments application lets you gather a variety of application performance metrics, such as memory and network use.

2. The Shark Application
The Shark application lets you view system-level events, such as system calls, thread-scheduling decisions, interrupts, and virtual memory faults.


Note:
When performance problems in your code are more related to the interaction between your code, iOS, and the hardware architecture of the device, you can use Shark to get information about those interactions and find performance bottlenecks.

2010年5月27日 星期四

nil vs Nil vs Null vs NSNull null

nil: A null pointer to an Objective-C object.
(#define nil ((id)0))

Nil: A null pointer to an Objective-C class. 

Null: A null pointer to anything else.
(#define NULL ((void*)0))

NSNull: A class defines a singleton object used to represent null values in collection objects (which don’t allow nil values).

[NSNull null]: The singleton instance of NSNull.

2010年4月12日 星期一

Something about Category and Extention

Category 和 Extention 有著非常相似的使用方式, 然而卻還是有些不同的使用情境. 基本上, Extention 是個
"anonymous" Category.
讓我們來復習一下 Category 的寫法:

@interface MyClassName ( MyCategoryName)
// extra methods' definitions
- (void)superShrimp;
@end

然後再看看 Extention
@interface MyClassName ()
// extra methods' definitions
- (void)superShrimp;
@end

2010年3月23日 星期二

function pointer in C++ to boost::function

Effective c++ item 35 舉了一個有趣的例子GameCharacter,

主要的精神在於利用function pointer把真正計算血量的部份,交給專門計算血量的function。達到像Strategy pattern可以隨時抽換實作內容的目的。

一開始看到後面boost時沒什麼fu,主要的原因在於自己對原本c++要怎麼delegate function的實作方式不熟,所以當後面進階的boost::function跟boost::bind的觀念導入後,心中只剩OS:這哪裡方便了?一點都不蝦阿~為了不模糊焦點,我們先不管pattern怎麼用,直接看看function pointer in standard C++的技巧。

2010年3月12日 星期五

你是雞,是豬,還是鬥雞?

在看Scrum的時候連帶看到了一個寓言The Chicken and the Pig

A pig and a chicken are walking down a road. The chicken looks at the pig and says, “Hey, why don’t we open a restaurant?” The pig looks back at the chicken and says, “Good idea, what do you want to call it?” The chicken thinks about it and says, “Why don’t we call it ‘Ham and Eggs’?” “I don’t think so,” says the pig, “I’d be committed, but you’d only be involved.”

大意是做出一份有雞蛋與培根/火腿的早餐,雞跟豬各自扮演的角色,用來比擬在一個專案或產品內每個人的角色。

Scrum軟體開發工具與方法—系列講座 (一) 課後雜記

昨天公司給我去參加外部課程的機會,在此先感謝一下老闆 (逢迎拍馬才是升官之道)
趁還有記憶在這寫一下筆記,以便之後準備公司內部報告。

2010年3月4日 星期四

Razorcap Studios

推一下 http://www.razorcap.com 作者是我當兵時候的學長,一直都在遊戲軟體業耕耘,現在也開始玩iPhone Programming了 超蝦~ Razorcap這名字的由來也很酷,請學長有空可以跟大家介紹一下 :)

2010年2月6日 星期六

C++物件模型之二

今天要上一道小菜: constructor initialization list

概念很簡單,以下的constructor寫得不好:
class Person {
    String _name;
    int    _age;
public:
    Person() {
        _name = 0;
        _age = 0;
    }
};
因為compiler會把它轉化成以下(*):
Person() {
    String tmpString(0);    // temporary String object been created
    String _name.String();
    _name = tmpString;      // copy assignment operator been called
    tmpString.~String();    // destruct temporary String object

    _age = 0;    // basic data type, set value directly
}

2010年2月1日 星期一

C++物件模型之一

記得十幾年前當C++正席捲整個軟體業的時候,有部分engineer拒絕從C進化到C++,主要的論點是C++ compiler在背後做太多事,以至於影響程式的效能。時至今日,C++早已成為許多軟體、系統的基本開發語言,但我覺得我自己對於compiler到底在程式碼上面動了甚麼手腳,掌握度還是不夠,於是開始研究起C++物件模型,並且想用一系列的文章和大家交流一下。

2010年1月20日 星期三

Why is Row Irrelevant in 2-Dimensional Arrays?

在傳入 2-dimensional array 到某個 function 裡面, 我們可以省略 row 的 subscript, 但是 column 的 subscript 確不可以省略.

ex:
void funtion(int array[][5]);

從 reference 查到的原因是因為, C 必須知道有多少 column, 所以他才可以正確的找到每個row的起點在哪.

我們來看看可以作為存取 2-dimensional 資料的宣告方式.

2010年1月19日 星期二

do while(false)

常在一些open source看到do while(false)的寫法,這樣一次call function只執行一次的code有甚麼優點呢?
可不可以用if(flag)的方式取代? 是不是覺得多此一舉或有其他更好的替代方法,討論看看。


2010年1月18日 星期一

enum

  • 以前我們在Effective C++ 有看過, 用enum取代 #define 跟 const 可以避免錯誤。
  • 許多遊戲engine 或包含大量UI的AP會使用enum管理音效, 貼圖等recourse。
  • enum還有個有趣的技巧叫 enum hack, 方便我們針對enum眾多recourse 的物件寫基本的測試程式。
請看以下宅力十足的code


2010年1月7日 星期四

Data structure alignment

前些時候將Structure內的資料以raw data的方式在處理時,才發現到原來Structure內的element並不是緊密相連在一起的。如以下例子:

2010年1月5日 星期二

X = X & X-1 Trick

最近在寫練習的時候看到這個有趣的習題, 相信很多人已經知道了,
就是在 2's complement 裡面, X = X & X-1, 會移除 X 裡面最右邊的 1,
在 C 裡面, 只要在 unsigned (或者全為正數)的變數裡面, 就可以用這個方法,
主要原因, 我想應該是在 2 進位的體系下, 只要讓某個值少 1, 就會讓那個值最後的一個1的右邊數值產生借位, 而造成了一個很有趣的 Pattern如下: