v8 :: Isolate和v8 :: Context之间到底有什么区别? [英] What exactly is the difference between v8::Isolate and v8::Context?

查看:606
本文介绍了v8 :: Isolate和v8 :: Context之间到底有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

V8中这些对象之间的区别/联系是什么?上下文是否属于"隔离对象,反之亦然?

What is the difference/connection between these objects in V8? Does a context "belong" to an Isolate or vice versa?

我知道单个隔离只能一次被一个线程访问(我猜这就是v8 :: Locker吗?).

I know that a single Isolate may only be accessed by one thread at a time (and that's what v8::Locker is for I guess?).

我已经仔细阅读了文档,但似乎无法掌握这些概念-感谢您提供任何帮助!

I've looked through the docs but I can't seem to get a grasp on these concepts - any help is appreciated!

推荐答案

我确定以下内容是一种简化,但对我有用.

I'm sure the following is a simplification, but it works for me.

隔离是V8运行时的独立副本,包括堆管理器,垃圾收集器等.一次只能有一个线程访问给定的隔离,但是不同的线程可以访问不同的线程同时隔离.

An isolate is an independent copy of the V8 runtime, including a heap manager, a garbage collector, etc. Only one thread may access a given isolate at a time, but different threads may access different isolates simultaneously.

但是,隔离不足以运行脚本.您还需要一个全局(根)对象. context 通过将隔离堆中的一个对象指定为全局对象来定义完整的脚本执行环境.

An isolate is not sufficient for running scripts, however. You also need a global (root) object. A context defines a complete script execution environment by designating an object in an isolate's heap as a global object.

因此,不仅可以在给定的隔离中存在"许多上下文,而且它们还可以轻松安全地共享任何或所有对象.那是因为它们的对象实际上属于隔离对象,并受到隔离对象的排他锁的保护.

Therefore, not only can many contexts "exist" in a given isolate, but they can also share any or all of their objects easily and safely. That's because their objects actually belong to the isolate and are protected by the isolate's exclusive lock.

这篇关于v8 :: Isolate和v8 :: Context之间到底有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆