Re: [問題] HW4 /ref/memTest.debug的輸出疑問
關於 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
11/19 11:42, 1F
推
11/22 01:10, , 2F
11/22 01:10, 2F
→
11/22 01:13, , 3F
11/22 01:13, 3F
→
11/22 01:14, , 4F
11/22 01:14, 4F
→
11/22 01:15, , 5F
11/22 01:15, 5F
→
11/22 01:15, , 6F
11/22 01:15, 6F
→
11/22 01:16, , 7F
11/22 01:16, 7F
→
11/22 01:16, , 8F
11/22 01:16, 8F
→
11/22 01:17, , 9F
11/22 01:17, 9F
→
11/22 01:18, , 10F
11/22 01:18, 10F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):