
⓪蕭沖 編著
話說自windows 8開始,在windows 8的應用程式大致上被分為二種: 一種就是「桌機」應用程式,這與過去的應用程式沒什麼大不同。另一種就是Metro-Style App。這種應用程式,目前正式的說法叫「Windows Store App」,因為metro style這個詞有一些法律上的問題。不過為了簡易一點的說明,以下我稱它叫 metro app。
先來說說 metro App 與傳統的desktop應用程式有什麼不同? 我個人覺得最主要的不同在於安全性。metro app與iphone上的app真的超像的,也就是app被局限在一個sandbox裡,不能隨意的存取他人的app或是重要的系統資源,比如說系統的根目錄等。metro app裡的目錄只有三個Local folder、Roaming folder 、Temp folder,因此想搞鬼太不容易,這點若有開發iphone app的人應該可以感受很深! 當然,metro app還有一個很大的不同,那就是外觀(UI),使用windows 8的介面後就會知道不同在哪裡…
ok,以上說了一堆,還是沒講到windows run time :p。總要有個前因嘛! 為了達到 metro app的風格、安全等等,當然相對的windows api就要有所改變,不然如何限制不能讀系統檔之類的,你說是吧?! metro app 被限制要使用WinRT這個framework(我不稱它是api)來開發。
aftcast 發表在 痞客邦 留言(0) 人氣(4,395)
⓪著作: 蕭沖
這是自己的一個筆記,關於使用dos命令來組裝數個mp3為一個檔。
md tmp
copy ???????c.mp3 tmp\??????? /y
FOR /F "eol=_ tokens=1,2*" %%i in ('dir tmp /AA /B') do copy /b ..\ac.mp3+%%ic.mp3+..\at.mp3+%%it.mp3+..\ae.mp3+%%ie.mp3 A%%i.mp3 && copy /b ..\nc.mp3+%%ic.mp3+..\nt.mp3+%%it.mp3+..\ne.mp3+%%ie.mp3 N%%i.mp3
rd /s /q tmp
aftcast 發表在 痞客邦 留言(0) 人氣(251)
aftcast 發表在 痞客邦 留言(0) 人氣(993)
⓪著作: 蕭沖
何謂thread-safe? 這個問題我看過許多論壇都有討論過,都總讓人覺得不很滿意。在此,筆者想要用更logical的方式來把議題說清楚。首先,我們要了解它的定義! 定義若都不明白就難以判別安不安全了!
aftcast 發表在 痞客邦 留言(7) 人氣(44,318)
⓪編著: 蕭沖
我們知道dll最主要的用途就是在於程式碼共享。而共享的過程中又會演生出全域資料(變數)是否共享的問題。
在多個process間共用同一個dll時,變數的共享與否是靠二個機制:
1/ 不共享全域變數 : 使用copy-on-write的觀念來處理 ( windows 系統自動預設是如此)
2/ 共享全域變數: 我們可以透過把變數放入一個share的segment的記憶體區段內,然後process間就可以共用。
aftcast 發表在 痞客邦 留言(2) 人氣(2,560)
⓪編著 :蕭沖
Thread Pool
1/ Create map container of thread data MAY including idle property for later SetEvent, event handle property for Reset event later, thread handle property for close handle later .....by thread id as its key.
2/ Create WorkItem Queue (list for insert priority item or deque for normal queue) data with object,parameter pointer,function pointer.....
3/ Create thread function with thread map container parameter. Impelement function as : get event handler by thread id key from container, WaitForMultipleObjects for handler just get and more utra event handler like shutdown notify. Or using simple semaphore mechanism. Get WorkItem from Queue, and call funtion. Keep looping...
4/ Create threads and insert each thread data into map.
5/ Queue the WorkItem and set event handler for each idle thread in map.
One thread can create its own event object, and be controled after queue work.
Semaphore is a global object, and every thread check it to see if it's count greater than 0,
if yes, then go work, if equal to 0, then keep waiting....
Multithread Socket programming
1/ normal model is after listening imcoming request.... loop for accept call.
2/ accept function is a bloking function, ie, if there's no request, it won't return, for this reason,
process beter create one thread to create server socket and binding and listening....
3/ when accept call returned, it create a new client socket for further communication with client.
4/ create a thread to deal with this new client socket for sending msg or rcv msg....
Traditional model is just like above, it using one thread per connection. and dynamically create thread.
Threads are created and then terminated, cycling....but this may cause taking much overhead.
Using thread pool for deal with client sockets is a good ideal for saving resource.
PS.The other model is using IOCP model for more robust and scalable....
aftcast 發表在 痞客邦 留言(0) 人氣(1,596)
⓪編著 :蕭沖
總的來說,Socket 可分為二種模式 : blocking mode, non-blocking mode。
要使socket成為non-blocking mode只要設定ioctlsocket為non-blocking mode就可以,然而,若配合使用了blocking functions,會使得讀/取不到資料時產生WSAEWOULDBLOCK的error。因此若要成功而完整的使用non-blocking mode,就必需配合適當的socket IO models。
Socket I/O 有六種模型:blocking, select, WSAAsyncSelect, WSAEventSelect, overlapped, and completion port。
針對不同的模型,我以一個虛擬的例子來說明: 假設有128條水管可以出水,但每一條出水的時間不同,且有快有慢,若我們的任務是在每一條水管必需各裝3桶水,那麼我們可以達成的方法有: (人數相當於thread的數量,水管數相當於socket數,水桶相當於傳送或接收的Buffer)
aftcast 發表在 痞客邦 留言(2) 人氣(7,759)