Re: [問題] HW4 /ref/memTest.debug的輸出疑問

看板EE_DSnP作者 (Ric)時間11年前 (2012/11/18 17:37), 編輯推噓2(208)
留言10則, 3人參與, 最新討論串2/2 (看更多)
關於 recycle lists 的順序,有兩點注意一下應該就會跟 ref 一樣了。 1. _recycleList[0] ~ _recycleList[255] 在 class MemMgr 的 constructor 就被 construct,所以只要它們的 numElm() != 0,在 mtprint 時一定會被印在前面 ==> 這點你們不用管他 2. 在 "MemRecycleList<T>* MemMgr::getMemRecycleList(size_t n)" 的 spec 有說: // [Note]: This function will be called by MemMgr->getMem() to get the // recycle list. Therefore, the recycle list is first created // by the MTNew command, not MTDelete. 所以從 MTNew command 到 new operator 到 MemMgr::getMem(t), 我們必須呼叫 "size_t n = getRecycleIdx(t)" 去拿到 array size "n", 再檢查看看 "getMemRecycleList(n)" 的 numElm() 是不是空的, 如果不是空的,則從 recycle list 拿到 recycled memory, 但如果是空的,則根據 spec 應該就要先產生一個 MemRecycleList (size = n), 塞到對應的 MemMgr::_recycleList[.] 的最後面,回到 getMem(t), 再繼續從 MemMgr 的 _activeBlock 去要 memory. ==> 所以 getRecycleIdx(t) 以及 getMemRecycleList(n) 一定要照這寫。 ※ 引述《stmharry (橘子)》之銘言: : 標題: [問題] HW4 /ref/memTest.debug的輸出疑問 : 時間: Sun Nov 18 15:30:35 2012 : : 我把 /tests/run 的內容改了一下,拿去跑reference program : : (簡單來說就是把dofile都拿去餵 /ref/memTest.debug) : : 可是對於某處的MTPrint結果有一點疑問。 : : 我把output檔案放在這裡: : : http://tinyurl.com/buw7szf (2.54MB,可以自己跑) : : ---問題開始--- : : 理論上回收的時候,先回收的size,會先住進linked list吧! : : 比如: : : Recycling 0x64acc80 to _recycleList[418] : ...(some other stuff) : Recycling 0x66af4f0 to _recycleList[162] : : 那又因418 % 256 = 162 % 256 = 162,他們會住進同一個linked list,變成 : : MemMgr::_recycleList[162] : | : v : MemRecycleList<T> ┌--> MemRecycleList<T> : _arrSize = 418 | _arrSize = 162 : _first = 0x64acc80 | _first = 0x66af4f0 : _nextList --------------┘ _nextList --------------> NULL : : 所以使用MTPrint指令印出Recycle list的時候,traverse應該會先跑過418,再跑到162 : : 可是...reference跑出來的結果竟然是162先印,再印418... : : (請參考檔案第95282行末及95283行行首) : : 這個相異處我卡了好久~"~ : : 請問各位板大有任何解釋嗎?Q____Q : : 謝謝認真看完的人^____^ : : -- : ※ 發信站: 批踢踢實業坊(ptt.cc) : ◆ From: 140.112.245.223 : → Phantasnix:作業doc的要求(見Command"MTPrint"那裏)就是照升序印出 11/18 15:59 : 推 ypf791:被誤導了.... 11/18 16:00 : → Phantasnix:又有關print的部分都是事先寫好的,只能在回收時就排好 11/18 16:00 : → ypf791:size<256的recycleList打從memMgr建起來就存在了 11/18 16:01 : → Phantasnix:應該不能照提示add to the last MemRecycleList 去做.. 11/18 16:01 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.36.62.74

11/19 11:42, , 1F
我懂了!!!輸出跟ref一樣惹!!!<( ̄︶ ̄)>
11/19 11:42, 1F

11/22 01:10, , 2F
問一下,作業document要求要升序排,可是這樣並不能保
11/22 01:10, 2F

11/22 01:13, , 3F
證印出升序(塞最後的不一定最大)。
11/22 01:13, 3F

11/22 01:14, , 4F
follows the ascending order of the array size % R_SIZE
11/22 01:14, 4F

11/22 01:15, , 5F
注意,是 "array size % R_SIZE" 哦!!
11/22 01:15, 5F

11/22 01:15, , 6F
do4 ref的最後print:10->2058->266->522->778->1034
11/22 01:15, 6F

11/22 01:16, , 7F
"array size % R_SIZE" 相同時則按照上述產生 recycle list
11/22 01:16, 7F

11/22 01:16, , 8F
的時序印出來。
11/22 01:16, 8F

11/22 01:17, , 9F
所以同個recycle index的不用照升序排?
11/22 01:17, 9F

11/22 01:18, , 10F
嗯好,謝謝教授
11/22 01:18, 10F
文章代碼(AID): #1GgAnM2x (EE_DSnP)
文章代碼(AID): #1GgAnM2x (EE_DSnP)