《小记忆体软体设计》PPT课件.ppt

上传人:牧羊曲112 文档编号:5500576 上传时间:2023-07-14 格式:PPT 页数:58 大小:392.51KB
返回 下载 相关 举报
《小记忆体软体设计》PPT课件.ppt_第1页
第1页 / 共58页
《小记忆体软体设计》PPT课件.ppt_第2页
第2页 / 共58页
《小记忆体软体设计》PPT课件.ppt_第3页
第3页 / 共58页
《小记忆体软体设计》PPT课件.ppt_第4页
第4页 / 共58页
《小记忆体软体设计》PPT课件.ppt_第5页
第5页 / 共58页
点击查看更多>>
资源描述

《《小记忆体软体设计》PPT课件.ppt》由会员分享,可在线阅读,更多相关《《小记忆体软体设计》PPT课件.ppt(58页珍藏版)》请在三一办公上搜索。

1、2023/7/14,1,小記憶體軟體設計,李俊宏,Outline,IntroductionSmall architectureSecondary storageCompression Small data structureMemory allocation,Introduction,小記憶體軟體應用Mobile computingEmbedded systemSmall session in serverMain frameSmall computerWeb serverJVMLimited extendibilityOld PC or ServerLarge data(multimedia

2、),Mobile computing devices,Picture of AutoPC,Beaming from HPC to AutoPC,作業系統 for PDA,LinuxPalm OSWin CE OSREX OSSymbian OSAndroidOthers,Andorid Demo,記憶卡,Compact Flash(CF),Smart Media(SM),Memory Stick(MS),Multi Media Card(MMC),Secure Digital(SD),PDA OS 電源管理,Sleep mode(turn off)System ClockInterruptRA

3、M Doze modeLCDDigitizerMain clockProcessor clockRunning mode(1 sec)Processor executing,程式的執行(PALM),Preemptive multitaskingUser Interface Application Shell(UIAS)一次只執行一個程式Launch code告知應用程式開始和顯示使用者介面啟動事件迴圈Event,記憶體的管理,RAM in Palm OS,記憶體的管理(storage RAM),記憶體的管理(storage RAM),記憶體受限的問題的一般解法,減少靜態與全域變數的數目減少記憶

4、體的使用遞迴函數可能造成堆疊空間不足降低執行檔的體積降低 Bitmap 解析度,避免使用 WAV 檔案動態配置記憶體要檢查是否配置成功一次要足程式需要的記憶體,還有其他的方法嗎?,Small architecture,IntroductionMemory limitSmall interfacesPartial failureCaptain OatesRead only memoryHooks,Introduction,如何管理整個系統所用的記憶體記憶體區段數量大小如果受到限制會束縛整個系統系統由多個元件組成元件可由不同團隊完成元件的記憶體需求量會動態改變簡單的設計-Monolithic Sy

5、stems只適用於簡單系統讓每個元件管理自己的記憶體運用狀態,Introduction(cont.),Memory,module,module,module,module,module,module,Monolithic Systems,Decomposed system組件設計組件互相連結方式組件共同政策,Introduction(cont.),設計組件介面須考慮之問題記憶體的可剪裁性(Tailorability)不同情形下使用相同組件可能會有不同的記憶體需求提供記憶體操控的方法以精確配置記憶體Vector v=new Vector(10)v.ensureCapacity(20)v.trim

6、ToSize()讓客戶負責管理組件運用callbacks管理記憶體讓客戶提供自已須要的記憶體配置函數記憶體策略,Pattern 4:Strategy 把演算法則整個換掉,Strategy:戰略,先提供配置記憶體的和release記憶體的函式界面,實作時再實作出特定策略.,在small architecture 中的問題,How to allocate memory?How to reduce communication load?How to process unpredictable memory requirement?How to satisfy the most important m

7、emory requirement?How to use the read only memory(ROM)?How to modify the data in ROM?,How to allocate memory?,問題如何在多個組件之間分配記憶體解答Memory limit(fixed sized heap,memory partitions)為每個元件設置記憶體限額,超出限額的請求,予以拒絕.描述系統包含多個組件,每個組件有各自的記憶體需求組件的記憶體需求隨程式的執行而動態變化記憶體有限,如果一個組件霸佔太多記憶體,會妨礙其他組件工作設計者可以為每個任務設一個合理的記憶體上限,How

8、to allocate memory?,步驟記錄當前每個組件配置的記憶體數量如修改組件的記憶體配置常式,使其計算目前所使用的記憶體數目確保組件所配置的記憶體數量不超過分配限額.理想狀態下應當透過試驗,檢視記憶體用量的手段來為每個組件事先設定限額.,How to allocate memory?,結果因每個組件的記憶用量都有限額,所以組件可獨立測試(system predictability)容易找出那些組件因記憶體不足而產生問題(localization)可能會產生問題的情形一個任務(task)正常工作,但另一任務因記憶體不足而失敗因任務大量通訊所引發的錯誤Memory fragmentati

9、on waste,How to allocate memory?,實做攔截記憶體管理操作函式並加以修改以追蹤記憶體使用情形(如c+的 new,delete)組件各自使用分離的heap各自管理分離的行程,Process in Memory,Temporary data:Function parameterReturn addressLocal variables,Global variables,Run time memory,Example 1:限制物件所使用記憶體總量,class MemoryRestrictedClass public:enum LIMIT_IN_BYTES=10000;s

10、tatic size_t totalMemoryCount;void*operator new(size_t aSize);void operator delete(void*anItem,size_t aSize);size_t MemoryRestrictedClass:totalMemoryCount=0,實作記憶體限制物件,Example 1:限制物件所使用記憶體總量,void*MemoryRestrictedClass:operator new(size_t aSize)if(totalMemoryCount+aSize LIMIT_IN_BYTES)throw(bad_alloc(

11、);totalMemoryCount+=aSize;return malloc(aSize);void*MemoryRestrictedClass:operator delete(void*anItem,size_t aSize)totalMemoryCount-=aSize;free(char*)anItem);,在new 方法中檢查是否超過限制,記錄記憶體使用情形,記錄記憶體使用情形,Example 2:限制物件實體數量,class RestrictedClassstatic final int maxNumberOfInstances=5;static int numberOfInsta

12、nces=0;public RestrictedClass()nunberOfInstances+;if(numberOfInstances maxNumberOfInstances)System.gc();/確認所有的垃圾都被回收if(numberOfInstances maxNumberOfInstances)throw new OutOfMemoryError(maxNumberOfInstances5);,最大物件實體數量,再丟出異常訊號,Public void finalize()-numberOfInstances;,物件終結時要作的動作,Memory limit applicat

13、ion,UNIX(for user process)EPOC(heap maximum size)WinCE(process usage memory upper bound,data usage memory upper bound)JVM(total heap size,java process size),練習,請設計一物件,其有6個函式,主程式可以呼叫這6個函式:1:function12:function23:function34:closef15:closef26:closef3假設每次呼叫前三個函式,都會配置10,20,30byte的記憶體,而呼叫後三個函式可以釋放相關記憶體.請限

14、制整個物件的記憶體使用在100byte內.如果超過記憶體限制的話,物件應給主程式記憶體不足的訊息.請撰寫此物件及其測試程式,How to reduce communication load,問題各組件負責管理自理自身記憶體之運用組件透過介面彼此溝通如何降低組件介面溝通成本解答Small interfaces設計出讓客戶端得以控制資料傳輸的介面描述系統包含多個組件,每個組件有各自的記憶體需求組件透過介面彼此進行通訊通訊可能要配置額外的記憶體資料提供者可能需要通用的介面,提供不同的資料型態給不同的模組,使記憶體需求大增,How to reduce communication load,步驟將介面之

15、間的資料傳輸量最小化決定資料傳輸的品質程度,How to reduce communication load,結果傳送用記憶體生命週期很短,可減少Enhancing predictability,locality,design quality,and maintainabilitySupporting advance real time behavior須考慮的問題Programmer disciplineProgrammer effortTest cost,How to reduce communication load,實做Pass by value vs.pass by referenc

16、eExchanging memory across interfacesLending:客戶出借記憶體給服務提供者Borrowing:客戶獲服務提供者所擁有物件的存取權Stealing:客戶接收服務提供者配置的物件,並負責歸還Incremental interfaces一次只傳部份資料,分多次傳完,Lending客戶出借記憶體給服務提供者,Client object,Provider object,d:Data,1.Get(d),1.1 Set(1),DocumentProperties d=new DocumentProperties();wordProcessor.getCurrentDo

17、cumentProperties(d);.long docsize=d.getSize();long doctime=d.getEditTime();.d=null;,將d借給wordProcessor讓它進行處理,Client 對d進行處理,委託provider作一些事,釋放,Borrowing客戶獲服務提供者所擁有物件的存取權,Client object,Provider object,d:Data,1.Get():d2.Release(d),1.1 Set(1),DocumentProperties d=wordProcessor.getDocumentProperties();long

18、 docsize=d.getSize();long doctime=d.getEditTime();.wordProcessor.releaseDocumentProperties(d);,Stealing客戶接收服務提供者配置的物件,並負責歸還,Client object,Provider object,d:Data,1.Get():d,1.1 new(1),2.delete,DocumentProperties d=wordProcessor.getDocumentProperties();long docsize=d.getSize();long doctime=d.getEditTim

19、e();.d=null;,管理責任,Incremental interfaces,使用情形To pass a sequence or collection of data itemsLimited memoryFragmented memory 實作Multiple callingPass data by lending iteratorGet data from writable iteratorPass data by borrow iterator,Client object,Provider object,Available space,1.Get():d,1.1 new(1),2.d

20、elete,Wanted space,Stealing:Required space available space,Multiple calling,Client object,Provider object,d2:Data,3.new(2),d1:Data,2.take(d1)4.take(d2)5.doAction(),1.new(1),Multiple calling(cont.),Case A:for(int i=0;i num_new_paras;i+)wordProcessor.addParagraph(parasi);wordProcessor.processAddedPara

21、graphs();,Case B:spookivity.findGhosts(transparent|dead);While(spookivity.moreGhostsToProcess()ghostScreen.addDisplay(spoolivity.getNextGhost();,將大量圖片分批傳到wordProcessor中,再讓wordProcessor處理,Pass data by lending iterator(client),The code in client:ghostScreen.displayAllGhosts(Spookivity.ghostIterator();

22、The code in component:Void displayAllGhosts(Iterator it)while(it.hasNext()displayGhost(Ghost)it.next();,傳遞一個”指向內部群集之一”的iterator,組件憑此iterator存取客戶資訊,Iterator:a BookShelf example,Books,BookShelfIterator,Pass data by borrow iterator,Iterator it=spookivity.findGhostsIterator(transparent|dead);While(it.ha

23、sNext()ghostScreen.displayGhost(Ghost)it.next();,借入一個iterator,Memory limit application,PalmOS APIEPOC APIClient-server interfacelendingUNIX file system callread(int fid,char*buf,int nchars);,How to process unpredictable memory requirement?,問題如何處理不可預見的記憶體需求解答Partial failure(graceful degradation)確保即使記

24、憶體用盡也要讓系統安全運作描述無論如何降低程式記憶體需求還是用光了寧可放棄非關鍵任務而不放棄關鍵任務持續不斷執行比完美執行更重要持續不斷執行比系統崩潰更是重要系統中的可用記憶體數量隨著時間變化很大,How to process unpredictable memory requirement?,State 1,State 2,State 3,Examples:,Displaying text,Displaying more text,Displaying still more text,Processing,Processing fails,拒絕動作,回到前一安全狀態,Out of memor

25、y state,alternative 1,alternative 2,進入降級模式,How to process unpredictable memory requirement?,結果Reduced memory requirementsEnhanced software usability,quality,reliability and predictabilitySupporting advance real time behavior須考慮的問題Programmer disciplineProgrammer effortSoftware global complexityTestin

26、g cost,How to process unpredictable memory requirement?,實作偵測記憶體耗盡到達安全狀態釋出資源降級模式未雨綢繆預防,How to process unpredictable memory requirement?,範例找出一種字型載入主記憶體Class StrapFont static Font myDefaultFont=new Font(Dialog,Font.PLAIN,12);/如果使用者要求之字型無法用便轉用佔較小記憶體之原始字型.public static Font defaultFont()return myDefaultF

27、ont;Public static Font font(String name,int style,int size)Font f;try f=privateGetFont(name,style,size);catch(BadFontException e)return defaultFont();catch(OutOfMemoryError e)return defaultFont();return f;,Partial failure application,EPOCDegraded modesPower PointPhotoShopMFC(plotting window),How to

28、satisfy the most important memory requirements?,問題如何滿足對記憶體的最重要需求解答Captain Oates(Cache release犧牲非絕對必要之元件所使用的記憶體,以滿足更重要的任務描述系統有在背景執行的元件應用程式為了提高性能,會以快取方存放資料使用者有相對於背景程式更重要的程式要執行,How to satisfy the most important memory requirements?,OperationSystem,Application 1(foreground app.),Application 2(background

29、 app.),Application 3,1.Memory req.,2.Memory low alarm,2.Memory low alarm,2.Memory low alarm,3.terminated,3.Reduced to minimum,3.discarded caches,How to satisfy the most important memory requirements?,結果Reduced memory requirementsEnhanced software usability,quality,reliability and predictability of m

30、emory usage須考慮的問題Programmer disciplineProgrammer effortSystem predictabilityTime performanceLocal complexity,How to satisfy the most important memory requirements?,實作程式詢問自己重要性偵測記憶體不足處理記憶體不足程序自動放棄比較不重要的資源,How to use the read only memory(ROM)?,問題如何處理唯讀的程式碼和資料解答Store the data to ROM將唯讀的程式碼和資料存在ROM中描述程式通常並不修改可執行碼程式不修改資源檔,檢索表和其他預先初始化過的資料,Hooks,ROM內的資料須要昇級說服使用者更新ROM使用Hooks,ROM Code,Function 1,Function 2,ROM,RAM,1,2,NewFunction 2,Project時程,需求分析Before 5/7設計Before 6/4產品demoBefore 6/25,

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号