Commit 5f00db1d authored by Adam P. Goucher's avatar Adam P. Goucher

Handle garbage collection correctly

parent 8cff1a3f
......@@ -50,18 +50,7 @@ namespace apg {
uint64_t total_bytes() { return htree.total_bytes(); }
void force_gc() { htree.gc_full(); }
bool threshold_gc(uint64_t threshold) {
if (threshold) {
uint64_t oldsize = htree.total_bytes();
if (oldsize >= threshold) {
// std::cerr << "Performing garbage collection (" << oldsize << " >= " << threshold << ")" << std::endl;
htree.gc_full();
// std::cerr << "Size reduced from " << oldsize << " to " << htree.total_bytes() << " bytes." << std::endl;
return true;
}
}
return false;
}
virtual bool threshold_gc(uint64_t threshold) = 0;
uint64_t counthandles() {
return htree.ihandles.size() + htree.handles.size();
......@@ -1407,6 +1396,19 @@ namespace apg {
return iterate_recurse1(hnode, mantissa, exponent, rule, history);
}
bool threshold_gc(uint64_t threshold) {
if (threshold) {
uint64_t oldsize = this->htree.total_bytes();
if (oldsize >= threshold) {
// std::cerr << "Performing garbage collection (" << oldsize << " >= " << threshold << ")" << std::endl;
this->htree.gc_full();
// std::cerr << "Size reduced from " << oldsize << " to " << htree.total_bytes() << " bytes." << std::endl;
return true;
}
}
return false;
}
};
......
......@@ -42,6 +42,21 @@ namespace apg {
*/
kivtable<nicearray<I, 4>, I, nicearray<I, 2> > biresults;
bool threshold_gc(uint64_t threshold) {
if (threshold) {
uint64_t oldsize = this->htree.total_bytes() + biresults.total_bytes();
if (oldsize >= threshold) {
std::cerr << "Performing garbage collection (" << oldsize << " >= " << threshold << ")" << std::endl;
this->htree.gc_full();
biresults.gc_traverse(false);
biresults.gc_traverse(true);
std::cerr << "Size reduced from " << oldsize << " to " << this->htree.total_bytes() << " bytes." << std::endl;
return true;
}
}
return false;
}
void printnode(hypernode<I> hnode) {
for (int y = 0; y < (16 << hnode.depth); y++) {
for (int x = 0; x < (16 << hnode.depth); x++) {
......
......@@ -5,7 +5,7 @@
int main() {
apg::lifetree<uint32_t, 4> lt(1500);
apg::streamtree<uint32_t, 1> st(1500);
apg::streamtree<uint32_t, 1> st(500);
/*
apg::pattern mkn(&lt, "16bo$15b2o$15bo3bo$14bo2bob2o$13b2o5bo$13bo2bo2bo$7bo5b2o4bo$7bobo5b2o"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment