Is it possible to either:
.) serialize contexts that have not been used recently to disk and
load them back into memory on demand
.) create a single context containing the javascript definitions once
and "link" new contexts to this context
.) reduce memory usage by creating a custom snapshot that contains my
javascript source at runtime
or would this go against v8's design ?
Is there any other way to reduce memory usage in this case?
std::auto_ptr<v8::ExtensionConfiguration> cfg;
// fill the array
for (size_t i=0; i<ext_names.size(); i++)
{
ext_ptrs.push_back(ext_names[i].c_str());
}
if (!ext_ptrs.empty()) cfg.reset(new v8::ExtensionConfiguration
(ext_ptrs.size(), &ext_ptrs[0]));
m_context = v8::Context::New(cfg.get());
if you could use python, the code should be like following in pyv8
<http://code.google.com/p/pyv8/source/browse/trunk/demos/ext.py>
from PyV8 import *
firstSrc = "function hello(s) { return 'hello ' + s; }"
firstPy = JSExtension("hello/javascript", firstSrc, register=False)
firstPy.register()
secondSrc = "native function title(s);"
secondPy = JSExtension("title/python", secondSrc, lambda secondfunc:
lambda name: "Mr. " + name, register=False)
secondPy.register()
with JSContext(extensions=['title/python', 'hello/javascript']) as
ctx:
print ctx.eval("hello(title('flier'))")