Tangled V8 and C + + | The second

Source: Internet
Author: User

Embedder ' s Guide (remember Fq)

If you have read Getting Started, you are now familiar with some of the key concepts of V8. For example, V8 is a standalone virtual machine, V8 the Handle,scope and context concepts.

This article further discusses these concepts and introduces other concepts that are critical to embedding V8 in C + +.

The V8 API provides features such as compiling and executing scripts, accessing methods and data structures in C + +, handling errors, and enabling security checks. Your application can use V8 just like some other C + + libraries, and only the header file v8.h that contains it.

V8 Design Elements provides some background knowledge about V8, and if you want to optimize your V8 application, you should be interested.

For readers of this article

This article is intended for C + + program apes that want to embed the V8 JavaScript engine in a C + + program while making JavaScript and C + + objects and methods visible to each other.

Handles (handle) and garbage collection

A handle pointer to a JavaScript object in the heap. The V8 garbage collector reclaims memory consumed by objects that cannot be accessed again. During garbage collection, the collector often moves objects to a different location (of course, the object is in the heap from start to finish). But don't worry, when the garbage collector moves the object, it automatically updates each handle to make sure they point to the original object.

How do you determine if an object has become garbage?

If an object is no longer accessible in JavaScript, and there is no handle pointing to it, it is considered garbage.

The garbage collector will dispose of the garbage from time to time to reclaim memory.

V8 's garbage collection mechanism is an important reason for V8 good performance, and if you want to know more about it, V8 Design Elements also contains relevant content.

Various types of handle:

A. Local handle (partial handle?) ) exists in the stack and is automatically cleared when the associated destructor is called. The life cycle of these local handles is determined by the handle scope that accommodates them. Handle scope is typically created at the beginning of a function call. When the handle scope is deleted, the garbage collector will kill and erase all the objects pointed to by handle in the handle scope. Of course, these objects can no longer be accessed in JavaScript, nor will they be directed by other handle. This type of handle can be found in getting Started (see "One").

The Local handle is in the form of:local<sometype>

Note: The handle stack is not part of the C + + stack, but the handle scope stack is embedded in the C + + stack. and handle scope can only be created in the stack, which means it can't be new (why?). Because the new stuff is in the heap.

B.

Tangled V8 and C + + | The second

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.