作者ric2k1 (Ric)
看板EE_DSnP
标题Re: [问题] HW4 /ref/memTest.debug的输出疑问
时间Sun Nov 18 17:37:23 2012
关於 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
1F:推 stmharry:我懂了!!!输出跟ref一样惹!!!<( ̄︶ ̄)> 11/19 11:42
2F:推 Phantasnix:问一下,作业document要求要升序排,可是这样并不能保 11/22 01:10
3F:→ Phantasnix:证印出升序(塞最後的不一定最大)。 11/22 01:13
4F:→ ric2k1:follows the ascending order of the array size % R_SIZE 11/22 01:14
5F:→ ric2k1:注意,是 "array size % R_SIZE" 哦!! 11/22 01:15
6F:→ Phantasnix:do4 ref的最後print:10->2058->266->522->778->1034 11/22 01:15
7F:→ ric2k1:"array size % R_SIZE" 相同时则按照上述产生 recycle list 11/22 01:16
8F:→ ric2k1:的时序印出来。 11/22 01:16
9F:→ Phantasnix:所以同个recycle index的不用照升序排? 11/22 01:17
10F:→ Phantasnix:嗯好,谢谢教授 11/22 01:18