]> gitweb.factorcode.org Git - factor.git/commitdiff
vm: don't keep more than 10 unused contexts around to prevent address space wastage...
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Sat, 18 Sep 2010 03:52:27 +0000 (20:52 -0700)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Sat, 18 Sep 2010 03:52:27 +0000 (20:52 -0700)
vm/contexts.cpp
vm/master.hpp
vm/vm.hpp

index 0ddd51e1bef3cddfb8e675a1994f3e9ac37076b4..3d3008c2aba18e3445955737cab2e97e1907fd7b 100644 (file)
@@ -111,8 +111,8 @@ void factor_vm::init_contexts(cell datastack_size_, cell retainstack_size_, cell
 void factor_vm::delete_contexts()
 {
        assert(!ctx);
-       std::vector<context *>::const_iterator iter = unused_contexts.begin();
-       std::vector<context *>::const_iterator end = unused_contexts.end();
+       std::list<context *>::const_iterator iter = unused_contexts.begin();
+       std::list<context *>::const_iterator end = unused_contexts.end();
        while(iter != end)
        {
                delete *iter;
@@ -159,6 +159,13 @@ void factor_vm::delete_context(context *old_context)
 {
        unused_contexts.push_back(old_context);
        active_contexts.erase(old_context);
+
+       while(unused_contexts.size() > 10)
+       {
+               context *stale_context = unused_contexts.front();
+               unused_contexts.pop_front();
+               delete stale_context;
+       }
 }
 
 VM_C_API void delete_context(factor_vm *parent, context *old_context)
index d2b9a5f709c49041850c40629317a5c0d36ac0ac..d4cd70f86706088ac05e1c7d7facbc1061240d88 100755 (executable)
@@ -24,6 +24,7 @@
 
 /* C++ headers */
 #include <algorithm>
+#include <list>
 #include <map>
 #include <set>
 #include <vector>
index 2cbedbcc7b6fad894a013fc93b2d126bfc733070..d9c7186c4eb490353cfbbc12c834224eacc7a28b 100755 (executable)
--- a/vm/vm.hpp
+++ b/vm/vm.hpp
@@ -35,7 +35,7 @@ struct factor_vm
        int callback_id;
 
        /* Pooling unused contexts to make context allocation cheaper */
-       std::vector<context *> unused_contexts;
+       std::list<context *> unused_contexts;
 
        /* Active contexts, for tracing by the GC */
        std::set<context *> active_contexts;