看板 EE_DSnP 關於我們 聯絡資訊
首先,我覺得當 _refCount == 0 時不應該就將 BddNodeInt* delete 掉, 因為它還存在 Hash 跟 cache 裏面。 當然你可以改變策略當 BddNodeInt* 被 delete 掉時就將它從 Hash 以及 Cache 抽掉 (其實不容易... 你可以想想看) 但是從 efficiency 的角度而言這樣並不一定好, 因為很有可能雖然目前的 _refCount == 0, 但是它很可能還會被其他的 ite() cache 到或是 Hash 到。 一般而言,BDD 的 garbage collection 是等到有必要的時候才會被呼叫的, 像是當 memory usage too high 的時候, 這時候再將 cache 裏面的 dead nodes 所對應的 Cache entries remove 掉, 再從 Hash 裏面 go through 所有的 node 去 delete 掉 BddNodeInt*。 For more details, you can refer to the second reference paper, or the last few lecture slides that we didn't cover. ※ 引述《dryman (dryman)》之銘言: : testBdd中可以正確執行 : 結果在執行./bdd中發現bandcmd等會錯誤 : 看了一下程式碼發現 : BAndCmd::exec(...) : { : ... : BddNode ret = BddNode::_one; : ... : cout << ret << endl; // 檢查-> 執行正確 : bddMgr -> forceAddBddNode(options[0], ret()); //加到_bddMap(string, size_t) : return CMD_EXEC_DONE; : } : 然後ret就被呼叫destructor了(--refcount == 0) : 連帶的他原本指向的bddNodeInt也被delete......orz|||||| : 我原本設計是沒人指到這個bddNodeInt就要delete它 : 不過看來我得讓bddNodeInt留著(即使refcount == 0) : 可是這樣很有可能造成多個bddNodeInt變成無人問津的垃圾 : 因為本來就會有很多local variable 的 BddNode... : 不delete不行啊 : 請問如何在不更改架構的情況下來解決這個問題? : 如果_bddMap等裡面存的是BddNode而非size_t就好了ˊˋ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.224.41.91
dryman:抽掉不容易..不過如果cache, hash裡面新增東西就++refCount 01/19 21:08
dryman:也是一種解決方式..更正cache用ref, hash要delete 01/19 21:08
ric2k1:我還是覺得這樣並不是很 engineering 的作法,garbage 01/19 21:46
ric2k1:collection should not be called too often. It should be 01/19 21:47
ric2k1:used as a last resort. 01/19 21:47
a3785lexx:我也同意老師...雖然我沒有作XD 但是如果太早砍掉 01/19 23:41
a3785lexx:可能以後還會要用到的時候就用不到,就要花時間建他... 01/19 23:41