1. 程式人生 > >修改wince儲存記憶體和程式記憶體

修改wince儲存記憶體和程式記憶體

首先解釋下這兩個東東

The RAM on a Windows CE–based device is divided into two areas: the object store and the program memory.

The object store resembles a permanent, virtual RAM disk. Data in the object store is retained when you suspend or perform a soft reset operation on the system. Devices typically have a backup power supply for the RAM to preserve data if the main power supply is interrupted temporarily. When operation resumes, the system looks for a previously created object store in RAM and uses it, if one is found. Devices that do not have battery-backed RAM can use the hive-based registry to preserve data during multiple boot processes.

The program memory consists of the remaining RAM. Program memory works like the RAM in personal computers — it stores the heaps and stacks for the applications that are running.

我承認我很懶,上面一段話的URL是ms-help://MS.WindowsCE.500/wcecoreos5/html/wce50conMemoryArchitecture.htm

具體的設定可以在系統啟動後,Control Panel -> System -> Memory 裡面看到。預設的是把記憶體五五開,一半給Storage Memory, 一半給Program Memory用。這樣顯然是不合算的。以64M的RAM為例, 啟動後Storage Memory 32M, 而因為沒有留出介面讓使用者往裡面拷東西, 任何時候in use都不會超過10M; Program Memory也是32M, 但啟動後就用掉27M, 實際上應用程式可用的記憶體只有5M, 一旦達到了上限, 那麼每前進一步都要很艱難地去釋放幾十K記憶體,然後用掉,再去釋放幾十K記憶體,如此迴圈,此時應用程式的執行速度狂慢無比.

劃分的方法也很簡單, 只不過可能沒人注意到而已.

說明在ms-help://MS.WindowsCE.500/wceosdev5/html/wce50lrfFSRAMPERCENT.htm 懶得看英文的人就繼續往下看

其實說白了就一句話, 在BSP的config.bib裡 CONFIG 區新增這個變數 FSRAMPERCENT = 0xXXXXXX, 但注意兩點,

(1) 必須寫在config.bib的CONFIG區裡, 不是plagform.bib不是config.reg等其他檔案而是config.bib,也不是config.bib檔案的任意地方而一定要在CONFIG REGION裡.
(2) FSRAMPERCENT這個變數一定得寫為FSRAMPERCENT, 不能寫成FSROMPERCENT不能寫成ILOVEU, 或者阿貓阿狗什麼的.

寫下這兩句的時候本人已經開啟無敵光環, 免疫一切雞蛋和西紅柿.

FSRAMPERCENT是一個4byte長度的十六進位制數, 我們用代數假設 FSRAMPERCENT = 0xQXYZ, 其中Q,X,Y,Z都是十六進位制數

那麼最終劃分給Storage Memory的大小 = ( Q + X + Y + Z ) / 0x400 * TOTAL_RAM_SIZE

以文中的例子來算, FSRAMPERCENT=0x10203040, 假設TOTAL_RAM_SIZE=64M, 那麼StorageMemory= (0x10 + 0x20 + 0x30 + 0x40) / 0x400 * 64M = 10M.

順路鄙視一下,WinXP自帶的計算器裡無法輸入和計算帶小數位的非十進位制數.