Sunday 22 August 2010

打爛沙盤問到篤

最近公司聘請了一位有一年工作經驗的人,這位新同事不是CS出身,故此對於基層C++的理論和應用,有點不明所然,對於Symbian C++更加是一頭霧水。但他連日來不斷努力煲書,甚至不惜工本買了《Symbian OS C++ for Mobile Phones - Volume 3》來煲,這本書我也沒有看過,全公司裡他是第一人,勁爆!而這本書似乎幫助他對Symbian C++有更好的了解,除了一個API:TDesC。他無法理解為何TDesC能夠讀取它的子類裡的數據。

他好學不倦的性格感動到我,也使我有很大的壓力,所以上Symbian.org去搵答案。如今Symbian已經是Open Source,可以直接看代碼,看看TDesC裡到底是怎樣做到它能解讀子類的數據:

http://developer.symbian.org/xref/oss/xref/Symbian3/sf/os/kernelhwsrv/kernel/eka/common/des16.cpp

例如:
1252 EXPORT_C HBufC16 *TDesC16::AllocLC() const
1253 /**
1254 Creates a new 16-bit heap descriptor, initialises it with a copy of this
1255 descriptor's data, and puts a pointer to the descriptor onto the cleanup stack.
1256
1257 The function leaves, if creation of the descriptor fails.
1258
1259 @return A pointer to the 16-bit heap descriptor, if creation is successful.
1260 The pointer is also put onto the cleanup stack.
1261 */
1262 {
1263
1264 HBufC16 *pH=HBufC16::NewLC(Length());
1265 *pH=(*this);
1266 return(pH);
1267 }

簡直是嘆為觀止!這是就中學程度吧?我呢種小三級有排都追唔上。

No comments: