作者ric2k1 (Ric)
看板EE_DSnP
标题Re: [问题] getlist
时间Thu Dec 14 15:42:55 2006
I don't quite understand your problem. However, please make sure ---
1. new ==> alloc ==> getMem() ==> "read" _recycleList[] (p = pop_front())
2. delete ==> free ==> "write" _recycleList[] (push_front(p))
In (1), if (_recycleList[]->_first == 0),
pop_front() should return 0,
and getMem() should try to acquire memory from _activeBlock.
In (2), if (_recycleList[]->_first == 0),
push_front(p) should make _recycleList[]->_first = p;
※ 引述《personhuang (Person)》之铭言:
: 请问一下 我似乎卡在这边
: 如果我mtn 一个东西 会去看_recycleList[]内是否有这样大小的
: 然後会进到_recycleList[m].getList(n)
: 若我new 单个obj 这时候 n=0 m=0
: 进去getList後 应该
: 是去判断里面有没有 _arrSize =n的 recyclelist
: 用ddd
: 在MemRecycleList<T>* ptr=this; ptr->_arrSize一开始就会等於0
: ptr->_first=0; 因为一开始没东西
: 如果我要free这边 是会到getMemRecycleList(0)->pushFront(p)
: 这边传入getMemRecycleList 然後到
: _recycleList[m].getList(n) 进去t的this的_arrSize 会是 0 ==n
: 但ptr->_first 也是0
: 所以会return 0
: 然後_recycleList[m]得到0 传回去再access就会crash掉
So I don't quite understand why you need to "access" the returned pointer from
_recycleList[m] in "free"...
==> You are "writing" to _recycleList, not "reading" when calling "free"...
: 在讲一次
: 1.如果我都判断他的_arrSize= =n 是就传回去 不是就继续找 找不到就传回NULL
: 这样我在new时 回传回非NULL(因为一开始this->_arrSize=n) getmem(t)
: 会在空的recycleList要值---错
: 我在free时 传入的_this 可以因为this->_arrSize=0 然後传回去使他可以去pushFront
: 2.如果我加上判断 this->_first =0 就传回NULL
: 这样new他就对了 他不会跟recyclelist要
: 可是在free时 传入的this->_first也=0 这样传回去再access会crash
: 不知道逻辑上我错在哪里 或是有哪种方法我没想到
: 希望有人看的懂 ...
: 谢谢指教
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.21.240
1F:推 personhuang:thx 12/14 18:17