Re: [問題] getlist的回傳到底是?
※ 引述《BattleRoyale (翔燄)》之銘言:
: 在
: getMemRecycleList 呼叫 _recycleList[m].getList(n)
: 在getList中 它回傳的是MemRecycleList<T>*
: 想請問說它到底要回傳什麼呢@@"
: 裡面的要求寫說:
: // Go through this and _nextList,
: // find out a recycle list whose "_arrSize" == "n"
: // If not found, create a new MemRecycleList with _arrSize = n
: // and add to the last MemRecycleList
: // So, should never return NULL
: 這邊的NULL跟原始reference code所說的return 0有一樣嗎?
: 我個人是覺得當找不到recyclist中有先前被回收的資料就要return 0
: 那有找到的話 是要retrurn什麼東西咧@__@
借一下之前的格式...
_recycleList[0] -> MemRecycleList
_arraySize = 0
_first -> Obj1 -> Obj2
_nextList -> MemRecycleList
_arraySize = 256
_first -> Obj3 -> Obj4
_nextList -> null
就是說今天假設要找一個_arraySize是256的MemRecycleList,
所以就先從_recycleList[0](因為256%256=0)所指到的MemRecycleList開始找,
如果沒有找到就找_nextList所指到的MemRecycleList,
在沒有就繼續找_nextList指到的MemRecycleList,
如果找到了就可以回傳this pointer或是前一個的_nextList。
一直到最後如果沒有找到(也就是說_nextList==0)
這樣就用_nextList去new一個新的MemRecycleList,
然後將這回傳。
大概就是這樣~
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.251.153
推
05/01 22:28, , 1F
05/01 22:28, 1F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):