vm: don't keep more than 10 unused contexts around to prevent address space wastage on low-budget operating systems like OpenBSD

release
Slava Pestov 2010-09-17 20:52:27 -07:00
parent e8b1a06dad
commit a36bd7fbaf
3 changed files with 11 additions and 3 deletions

View 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)

View File

@ -24,6 +24,7 @@
/* C++ headers */
#include <algorithm>
#include <list>
#include <map>
#include <set>
#include <vector>

View File

@ -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;