|
Bruce Eckel的一篇日志建議把self從方法的參數列表中移除,并把它作為一個關鍵字使用。 http://www.artima.com/weblogs/viewpost.jsp?thread=239003
Guido的這篇日志說明了self作為參數是必不可少的。 http://neopythonic.blogspot.com/2008/10/why-explicit-self-has-to-stay.html
第一個原因是保證foo.meth(arg)和C.meth(foo, arg)這兩種方法調用的等價(foo是C的一個實例),關于后者可以參見Python Reference Manual 3.4.2.3。這個原因理論上的意義比較大。
第二個原因在于通過self參數我們可以動態修改一個類的行為:
#
?Define?an?empty?class:
class
?C:
pass
?
#
?Define?a?global?function:
def
?meth(myself,?arg): myself.val?
=
?arg
return
?myself.val ?
#
?Poke?the?method?into?the?class:
C.meth?
=
?meth
這樣類C就新增了一個meth方法,并且所有C的實例都可以通過c.meth(newval)調用這個方法。
前面兩個原因或許都可以通過一些workaround使得不使用self參數時實現同樣的效果,但是在存在decorator的代碼中Bruce的方法存在致命的缺陷。(關于decorator的介紹可以參見http://www.python.org/dev/peps/pep-0318/)
根據修飾對象,decorator分兩種,類方法和靜態方法。兩者在語法上沒有什么區別,但前者需要self參數,后者不需要。而Python在實
現上也沒有對這兩種方法加以區分。Bruce日志評論中有一些試圖解決decorator問題的方法,但這些方法都需要修改大量底層的實現。
最后提到了另一種語法糖實現,新增一個名為classmethod的decorator,為每個方法加上一個self參數,當然這種實現也沒必要把self作為關鍵字使用了。不過我覺得這么做還不如每次寫類方法時手工加個self =_=
2008年評出了1998年最具影響力的PLDI論文,獲獎論文的作者將分攤1000美元的獎金(還沒一等獎學金多 -_-b)
2008 (for 1998): The Implementation of the Cilk-5 Multithreaded Language, Matteo Frigo, Charles E. Leiserson, and Keith H. Randall
Citation
“The 1998 PLDI paper “Implementation of the Cilk-5 Multithreaded
Language” by Matteo Frigo, Charles E. Leiserson, and Keith H. Randall
introduced an efficient form of thread-local deques to control
scheduling of multithreaded programs. This innovation not only opened
the way to faster and simpler runtimes for fine-grained parallelism,
but also provided a basis for simpler parallel recursive programming
techniques that elegantly extend those of sequential programming. The
stack-like side of a deque acts just like a standard procedure stack,
while the queue side enables breadth-first work-stealing by other
threads. The work-stealing techniques introduced in this paper are
beginning to influence common practice, such as the Intel Threading
Building Blocks project, an upcoming standardized fork-join framework
for Java, and a variety of projects at Microsoft.”
另外前幾年的獲獎paper有:
2007 (for 1997): Exploiting Hardware Performance Counters with Flow and
Context Sensitive Profiling, Glenn Ammons, Thomas Ball, and James R.
Larus
2006 (for 1996): TIL: A Type-Directed Optimizing Compiler for ML,
David Tarditi, Greg Morrisett, Perry Cheng, Christopher Stone, Robert
Harper, and Peter Lee
2005 (for 1995): Selective Specialization for Object-Oriented Languages, Jeffrey Dean, Craig Chambers, and David Grove
2004 (for 1994): ATOM: a system for building customized program analysis tools, Amitabh Srivastava and Alan Eustace
2003 (for 1993): Space Efficient Conservative Garbage Collection, Hans Boehm
2002 (for 1992): Lazy Code Motion, Jens Knoop, Oliver Rüthing, Bernhard Steffen.
2001 (for 1991): A data locality optimizing algorithm, Michael E. Wolf and Monica S. Lam.
2000 (for 1990): Profile guided code positioning, Karl Pettis and Robert C. Hansen.
兩者配合,更完美的知識管理方案
http://hi.baidu.com/qq303520912/blog/item/de5cba082db83e36e924889e.html
Endnote是目前國內科研人員使用最多的文獻管理軟件,功能最完備,各數據庫或大學圖書館等和它的兼容也是最好。它的Filter和style
也最為豐富,而且可以自己創建修改??纯粗車娜?,大部分都是Endnote的用戶。
Zotero作為一個新的文件管理系統,與Endnote相比還是稚嫩了些,特別對于國內數據庫的支持不佳,更是限制了它的應用。
不過,Zotero作為Firefox瀏覽器的插件,還是有一些特別之處。
第一,便攜。Firefox是有Portable版本的,當然Zotero也就是Portable了,也就是說可以把火狐和Zotero放到U盤里,在任何一臺電腦上都可以 使用。而Endnote就沒有這么方便了。
第二,便利。使用電腦時,我們使用瀏覽器的時間要大大多于Endnote的時間,遇到有用的文獻、網頁或者需要做筆記,直接使用Zotero更加省時省力。而且它自動收集網頁中文獻信息的功能也大大方便了操作。
第三,
分享。EndnoteX以后可以把一個library發送成一個檔案文件(.enlx),使得文獻交換更為方便。不過有時我們只需要幾條文獻時,這樣操作
就大動干戈了。當然Endnote也支持所選部分文獻的導出,但這樣有不能夠導出附件,包括圖片、PDF等(此處為個人經驗,是否Endnote也能導出
附件來還望您不吝賜教)。而Zotero就可以實現某條文獻所有內容(題錄、筆記、附件)的全部導出,而且可以為另一Zotero用戶所完整接受。
第四,跟蹤文獻的收集。很多數據都支持檢索式或者引文的提醒,會隨時把新的內容發送到郵箱或者以RSS的形式發布。一般來說,查看這些都需要瀏覽器。有了Zotero,我們可以在查看的同時收集下有用的文獻信息。
Zotero更適合于在日常工作、學習甚至娛樂時使用,而Endnote更適合在有明確目的時使用。有人說Zotero更像“知識管理軟件”,
而
Endnote就是為文獻服務的。兩者可以實現互補,在日常工作中使用Zotero收集零散的資料,積累一定量之后將文獻信息導入到Endnote中,使
用Endnote管理、引用文獻信息。至于PDF、圖片等附件的管理,我還是建議使用Zotero,方便且可以完整導出。
下面談一下Zotero和Endnote中文獻的互相導入。
Zotero導入Endnote:
1 選定文獻,右鍵點選”export selected items”;如果是導入整個Library或者cellection可在相應圖標上右鍵點選;
2 在彈出的對話框中選擇導出的格式為”Refer/BibIX”, 選擇文件目錄,保存文件,格式為.txt;
3 在Endnote中打開一個library,執行“files-import”;
4 在對話框中選擇剛才的.txt文件, Impott Option選Refer/BibIX,Text Translation選Unicode(UTF-8)。點確定后即可導入。
Endnote導入Zotero:
1 選擇文獻后,執行“files-export”;
2 選擇Output Style為Endnote Export,命名后導入,得到.txt文件。
3 在Zotero中執行“actions-import” ,選擇得到的文件,點確定即可導入。
上述導入方式僅能實現文獻題錄的導入。
BBS上的一個帖子,問題是 def?a(): ????def?b(): ????????x?+=?1 ? ????x?=?1 ????print?"a:?",?x ????b() ????print?"b:?",?x ? def?c(): ????def?d(): ????????x[0]?=?[4] ????x?=?[3] ????print?"c:?",?x[0] ????d() ????print?"d:?",?x[0] 運行a()會報UnboundLocalError: local variable ‘x’ referenced before assignment
但是運行c()會正確地顯示3和4。 原因在于原因在于CPython實現closure的方式和常見的functional language不同,采用了flat closures實現。 “If a name is bound anywhere within a code block, all uses of the
name within the block are treated as references to the current block.” 在第一個例子中,b函數x += 1對x進行賦值,rebind了這個對象,于是Python查找x的時候只會在local environment中搜索,于是就有了UnboundLocalError。 換句話說,如果沒有修改這個值,比如b中僅僅簡單的輸出了x,程序是可以正常運行的,因為此時搜索的范圍是nearest enclosing function region。 而d方法并沒有rebind x變量,只是修改了x指向的對象的值而已。如果把賦值語句改成x = [4],那么結果就和原來不一樣了,因為此時發生了x的rebind。 所以Python中的closure可以理解為是只讀的。 另外第二個例子也是這篇文章中提到的一種workaround:把要通過inner function修改的變量包裝到數組里,然后在inner function中訪問這個數組。 至于為什么Python中enclosed function不能修改enclosing function的binding,文中提到了主要原因還是在于Guido反對這么做。因為這樣會導致本應該作為類的實例保存的對象被聲明了本地變量。 參考網站:http://www.python.org/dev/peps/pep-0227/
acm queue 9月的雜志的主題是The Concurrency Problem,力推了Erlang這個語言,其中有篇文章簡單的介紹了下這個message-oriented語言。 查了下這個名字的讀法,正確的讀法應該是air-lang,這里元音a的發音和bang中的a一樣。 文章中的第一個程序就有點令人費解,主要原因在于Erlang的語法和一般的imperative language差別很大,和functional language比較類似,但是本質上也有很大的不同。 以Java的一個計數程序為例 //?A?shared?counter. public?class?Sequence?{ ????private?int?nextVal?=?0; ? ????//?Retrieve?counter?and?increment. ????public?synchronized?int?getNext()?{ ????????return?nextVal++; ????} ? ????//?Re-initialize?counter?to?zero. ????public?synchronized?void?reset()?{ ????????nextVal?=?0; ????} } 這個程序的功能不用多說了,一個同步的計數程序。它的Erlang翻譯版的代碼為 -module(sequence1). -export([make_sequence/0, get_next/1, reset/1]). ? % Create a new shared counter. make_sequence() -> spawn(fun() -> sequence_loop(0)end). ? sequence_loop(N) -> receive {From, get_next} -> From!{self(), N}, sequence_loop(N + 1)<SEMI> reset -> sequence_loop(0) end. ? % Retrieve counter and increment. get_next(Sequence) -> Sequence!{self(), get_next}, receive {Sequence, N} -> N end. ? % Re-initialize counter to zero. reset(Sequence) -> Sequence! reset. 初看這個程序自然是一頭霧水,不過程序的函數式風格味還是很濃的。 前面提到,Erlang是基于message的,或者說message sending機制是包含在語言系統內部的,語法就是 pid ! message 接下來再來分析這個簡單的程序。開頭兩行是模塊和函數聲明,略去。make_sequence開始這個進程,spawn/1內置函數創建一個新的進程,并返回pid到調用者。 初始時運行的函數是sequence_loop(0),這個函數接收兩種信息,用receive表達式聲明:如果收到形式是{From,
get_next}的信息,就返回當前的N并調用sequence_loop(N+1),這樣下一次收到同樣的信息時就能返回N+1了;reset則等價
于Java版本中的n=0語句。 get_next/1則是發送給pid為Sequence的進程 {self(), get_next}
這樣一個信息,上面解釋的sequence_loop/1函數收到這個信息后會返回一個 {self(), N}
的tuple給get_next/1,收到這個信息后get_next/1就能返回N這個值了。 最后reset/1函數則是發送給Sequence一個reset信息。 這個簡單的程序里能大致窺見一些Erlang的特點,尤其是它基于信息發送的本質。
09月 18, 2008 第一個testkernel在Xen中的載入The Definitive Guide to Xen中第二章的例子,make成功后運行xen create domain_config,報錯 Error: (2, ‘Invalid kernel’, ‘xc_dom_compat_check: guest type xen-3.0-x86_32 not supported by xen kernel, sorry\n’)
google之后發現是虛擬機類型設置的問題,運行xm info可以看到 xen_caps : xen-3.0-x86_32p
末尾的p表示Xen內核開啟了PAE模式,所以載入的kernel也必須開啟PAE,在bootstrap.x86_32.S中加入PAE=yes選項即可。 09月 25, 2008 DomainU中調用do_console_ioThe Definitive Guide to Xen第二章的Exercise,通過調用hypercall page中的console_io項輸出Hello World。 void?start_kernel(start_info_t?*?start_info) { ????HYPERVISOR_console_io(CONSOLEIO_write,12,"Hello?World\n"); ????while(1); } 但是默認選項編譯和啟動的Xen是不會保留DomainU中輸出的信息。參考drivers/char/console.c,可以看到主要有兩個選項控制了DomainU的do_console_io輸出: #ifndef?VERBOSE ????/*?Only?domain?0?may?access?the?emergency?console.?*/ ????if?(?current->domain->domain_id?!=?0?) ????????return?-EPERM; #endif
if?(?opt_console_to_ring?) { ????for?(?kptr?=?kbuf;?*kptr?!=?'\0';?kptr++?) ????????putchar_console_ring(*kptr); ????send_guest_global_virq(dom0,?VIRQ_CON_RING); } VERBOSE選項可以在編譯Xen的時候開啟debug選項,而opt_console_to_ring則是一個啟動選項,在grub的啟動選項中增加loglvl=all guest_loglvl=all console_to_ring即可。 重啟Xen后就能通過xm dmesg看到Hello World了。 09月 25, 2008 Xen: Remove support for non-PAE 32-bit看來我還是用Xen 3.1吧 = = Subject: [Xen-devel] [PATCH] xen: remove support for non-PAE 32-bitLink to this message From: Jeremy Fitzhardinge (jer…@goop.org) Date: 05/09/2008 04:05:34 AM List: com.xensource.lists.xen-devel Non-PAE operation has been deprecated in Xen for a while, and is rarely tested or used. xen-unstable has now officially dropped non-PAE support. Since Xen/pvops’ non-PAE support has also been broken for a while, we may as well completely drop it altogether. 10月 07, 2008 IA-32 Memory Virtualizationhttp://www.intel.com/technology/itj/2006/v10i3/3-xen/4-extending-with-intel-vt.htm 上圖為full virtulization的情況,即不修改Guest OS的行為時的解決方案。Xen為每個Guest OS維護了一張shadow page table,其中映射的地址為machine address。一種比較高效的方案是設置Guest OS的page table為只讀,當Guest OS試圖修改這個虛擬頁表時,發生page fault被Xen截獲,Xen修改shadow page table中相應的數據(把pseudo-physical address轉化成machine address)。另外一個優化是guest page table被修改時不修改shadow page table,只是把它放到一個待更新列表中,等Guest OS執行了刷新tlb的指令后再一次性更新。 The Definitive Guide to Xen上還提到了另一種基于full paravirtulization和shadow page table之間的方案。Xen把Guest OS的page table置為只讀,當Guest OS試圖修改page table時,Xen捕獲到page fault,把page directory中對應的入口置為無效,再把page table改成可寫讓Guest OS修改。由于page directory中對應的入口被設成無效了,下次訪問該地址時還是會發生page fault,這時候Xen再修改page directory和page table的對應項就行了。 這種方法意味著Guest OS中內核管理模塊直接和machine address打交道,而其他部分則仍然使用pseudo-physical address。另外這種情況下page directory不能被Guest OS修改。 另外Xen還用到了段機制,用來為Xen保留地址空間開始的64M內存。
好不容易找到的一個php,直接貼這兒了,方便其他網友。 wordpress的wp-syntax插件用的也是geshi,所以同樣也適用于wp-syntax <?php /************************************************************************************* ?*?erlang.php ?*?-------- ?*?Author:?Uwe?Dauernheim?(uwe@dauernheim.net) ?*?Copyright:?(c)?2008?Uwe?Dauernheim?(http://www.kreisquadratur.de/) ?*?Release?Version:?1\.0\.0 ?*?Date?Started:?2008-09-27 ?* ?*?Erlang?language?file?for?GeSHi. ?* ?*?CHANGES ?*?------- ?*?2008-09-27?(1.0.0) ?*???[?]?First?Release ?* ?*?2008-09-28?(1.0.0.1) ?*???[!]?Bug?fixed?with?keyword?module. ?*???[+]?Added?more?function?names??? ?* ?*?TODO?(updated?2008-09-27) ?*?------------------------- ?*???[!]?Stop?';'?from?being?transformed?to?'<SEMI>' ?*? ?************************************************************************************/
$language_data?=?array?( ????'LANG_NAME'?=>?'Erlang', ????'COMMENT_SINGLE'?=>?array(1?=>?'%'), ????'CASE_KEYWORDS'?=>?GESHI_CAPS_NO_CHANGE, ????'QUOTEMARKS'?=>?array('"'), ????'HARDQUOTE'?=>?array("'",?"'"),? ????'HARDESCAPE'?=>?array('\\\'',),? ????'ESCAPE_CHAR'?=>?'\\', ????'KEYWORDS'?=>?array( ????????1?=>?array( ????????????'module',?'export',?'import',?'author',?'behaviour' ????????????), ????????2?=>?array( ????????????'case',?'of',?'if',?'end',?'receive',?'after' ????????????), ????????3?=>?array( ????????????//?erlang ????????????'set_cookie',?'get_cookie',? ????????????//?io ????????????'format',?'fwrite',?'fread',? ????????????//?gen_tcp ????????????'listen',?'accept',?'close',? ????????????//?gen_server ????????????'call',?'start_link' ????????????) ????????), ????'SYMBOLS'?=>?array( ????????':',?'=',?'!',?'|' ????????), ????'CASE_SENSITIVE'?=>?array( ????????GESHI_COMMENTS?=>?false, ????????1?=>?true, ????????2?=>?true, ????????3?=>?true ????????), ????'STYLES'?=>?array( ????????'KEYWORDS'?=>?array( ????????????1?=>?'color:?#b1b100;', ????????????2?=>?'color:?#b1b100;', ????????????3?=>?'color:?#000066;' ????????????), ????????'COMMENTS'?=>?array( ????????????1?=>?'color:?#666666;?font-style:?italic;', ????????????2?=>?'color:?#009966;?font-style:?italic;', ????????????3?=>?'color:?#0000ff;', ????????????4?=>?'color:?#cc0000;?font-style:?italic;', ????????????5?=>?'color:?#0000ff;', ????????????'MULTI'?=>?'color:?#666666;?font-style:?italic;' ????????????), ????????'ESCAPE_CHAR'?=>?array( ????????????0?=>?'color:?#000099;?font-weight:?bold;', ????????????'HARD'?=>?'color:?#000099;?font-weight:?bold;' ????????????), ????????'BRACKETS'?=>?array( ????????????0?=>?'color:?#009900;' ????????????), ????????'STRINGS'?=>?array( ????????????0?=>?'color:?#ff0000;', ????????????'HARD'?=>?'color:?#ff0000;' ????????????), ????????'NUMBERS'?=>?array( ????????????0?=>?'color:?#cc66cc;' ????????????), ????????'METHODS'?=>?array( ????????????1?=>?'color:?#006600;', ????????????2?=>?'color:?#006600;' ????????????), ????????'SYMBOLS'?=>?array( ????????????0?=>?'color:?#339933;' ????????????), ????????'REGEXPS'?=>?array( ????????????0?=>?'color:?#0000ff;', ????????????4?=>?'color:?#009999;', ????????????), ????????'SCRIPT'?=>?array( ????????????) ????????), ????'URLS'?=>?array( ????????1?=>?'', ????????2?=>?'', ????????3?=>?'http://www.erlang.org/doc/man/{FNAMEL}.html' ????????), ????'OOLANG'?=>?true, ????'OBJECT_SPLITTERS'?=>?array( ????????1?=>?'->', ????????2?=>?':' ????????), ????'REGEXPS'?=>?array( ????????//?Variable ????????0?=>?'[A-Z][_a-zA-Z0-9]*', ????????//?File?Descriptor ????????4?=>?'<[a-zA-Z_][a-zA-Z0-9_]*>' ????????), ????'STRICT_MODE_APPLIES'?=>?GESHI_NEVER, ????'TAB_WIDTH'?=>?4 );
?>
依然是內網日志的匯總
1. sysenter的介紹 http://www.codeguru.com/cpp/w-p/system/devicedriverdevelopment/article.php/c8223
System Call Optimization with the SYSENTER Instruction by John Gulbrandsen Windows下的
2. The SLUB allocator slab的改進版本
http://lwn.net/Articles/229984/
http://lwn.net/Articles/229096/
Christoph’s response is the SLUB allocator, a drop-in replacement for the slab code. SLUB promises better performance and scalability by dropping most of the queues and related overhead and simplifying the slab structure in general, while retaining the current slab allocator interface.
Wider use may be in the cards: the SLUB allocator is in the -mm tree now and could hit the mainline as soon as 2.6.22. The simplified code is attractive, as is the claimed 5-10% performance increase. If merged, SLUB is likely to coexist with the current slab allocator (and the SLOB allocator intended for small systems) for some time. In the longer term, the current slab code may be approaching the end of its life.
3. Compilers and More: Parallel Programming Made Easy? http://www.hpcwire.com/features/Compilers_and_More_Parallel_Programming_Made_Easy.html
by Michael Wolfe, Compiler Engineer, The Portland Group, Inc.
4. OpenCL slides, SIGGRAPH '08 發信人: jjgod (while(!asleep()) sheep++;), 信區: CSArch 標? 題: SIGGRAPH 08 上的 OpenCL slides 發信站: 水木社區 (Mon Sep 15 01:32:03 2008), 站內
※ 來源:·水木社區 newsmth.net·[FROM: 125.33.176.*]
附件: munshi-opencl.pdf (1338 KB) 鏈接: http://att.newsmth.net/att.php?p.272.35430.226.pdf 全文鏈接:http://www.newsmth.net/bbscon.php?bid=272&id=35430
5. linux-gate.so http://www.trilithium.com/johan/2005/08/linux-gate/ linux下使用sysenter的機制
|