v8

garbage collection with node.js

大憨熊 提交于 2019-12-17 02:29:29
问题 I was curious about how the node.js pattern of nested functions works with the garbage collector of v8. here's a simple example readfile("blah", function(str) { var val = getvaluefromstr(str); function restofprogram(val2) { ... } (val) }) if restofprogram is long-running, doesn't that mean that str will never get garbage collected? My understanding is that with node you end up with nested functions a lot. Does this get garbage collected if restofprogram was declared outside, so str could not

如何高效地遍历 MongoDB 超大集合?

人盡茶涼 提交于 2019-12-16 15:41:38
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> GitHub 仓库: Fundebug/loop-mongodb-big-collection 本文使用的编程语言是 Node.js,连接 MongoDB 的模块用的是 mongoose 。但是,本文介绍的方法适用于其他编程语言及其对应的 MongoDB 模块。 错误方法:find() 也许,在遍历 MongoDB 集合时,我们会这样写: const Promise = require("bluebird"); function findAllMembers() { return Member.find(); } async function test() { const members = await findAllMembers(); let N = 0; await Promise.mapSeries(members, member => { N++; console.log(`name of the ${N}th member: ${member.name}`); }); console.log(`loop all ${N} members success`); } test(); 注意,我们使用的是 Bluebird 的 mapSeries 而非 map ,members 数组中的元素是一个一个处理的

JavaScript 对引擎、运行时、调用堆栈的概述理解

谁说我不能喝 提交于 2019-12-16 11:18:03
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> JavaScript 对引擎、运行时、调用堆栈的概述理解  随着JavaScript越来越流行,越来越多的团队广泛的把JavaScript应用到前端、后台、hybrid 应用、嵌入式等等领域。 这篇文章旨在深入挖掘JavaScript,以及向大家解释JavaScript是如何工作的。我们通过了解它的底层构建以及它是怎么发挥作用的,可以帮助我们写出更好的代码与应用。据 GitHut 统计显示,JavaScript 长期占据GitHub中 Active Repositories 和 Total Pushes 的榜首,并且在其他的类别中也不会落后太多。 如果一个项目越来越依赖 JavaScript,这就意味着开发人员必须利用这些语言和生态系统提供更深层次的核心内容去构建一个令人振奋的应用。然而,事实证明,有很多的开发者每天都在使用 JavaScript,但是却不知道在底层 JavaScript 是怎么运作的。 概述 几乎每个人听说过 V8 引擎的概念,而且,大多数人都知道 JavaScript 是单线程的,或者是它是使用回调队列的。 在这篇文章中,我们将详细的介绍这些概念,并解释 JavaScript 是怎么工作的。通过了解这些细节,你就能利用这些提供的 API 来写出更好的,非阻塞的应用来。如果你对

How to convert an Integer to a String in V8?

血红的双手。 提交于 2019-12-14 03:22:57
问题 I have the following V8 code: Local<String> getSumString(int32_t a, int32_t b){ int32_t sum = a + b; return String::Concat(String::New("The sum is: ") , String::New(sum)); } In the above function I want to add a and b , then want to return a string "The sum is: CALCULATED_SUM " . I'm having problems in converting the calculated sum to a String so that it can be concatenated with other String. 回答1: You don't say the nature of the error, but I'm guessing that the end of your output string is

v8 access to DOM

守給你的承諾、 提交于 2019-12-14 03:17:59
问题 I want to change the v8 engine in order to be able to intercept every access to DOM elements. As you know, v8 does not create the DOM tree. The browser creates the DOM tree. My question 1: how/where in the v8 source code, the DOM memory structure is delivered to v8. How can I do my interception with minimum effort? 回答1: I can't tell you exactly where the DOM is registered in V8, but I have some hints for you about where you can start your search. First, as the browser creates the DOM, you

emscripten: Memory leak with std::vector & std::map in c++ code

眉间皱痕 提交于 2019-12-13 16:16:05
问题 I want to know how to properly delete the memory of std::vector & std:: map allocated in c++ code. I am sharing my code here # include <vector> # include <stdio.h> # include <stdlib.h> //realloc # include <math.h> # include <map> # include <unordered_map> #include <emscripten/bind.h> using namespace emscripten; struct Edge{ // Coordinates of two vertices float c[6]; float normal[3]; int i1, i2; Edge() {}; Edge(const float * v1, const float * v2, const float * _normal, int _i1, int _i2) { i1 =

How to use linked libraries compiled with libc++ libstdc++ mixed

╄→гoц情女王★ 提交于 2019-12-13 16:06:54
问题 I am trying to write a script that uses a library compiled with clang and another library compiled with G++, I get the following error: ld.lld: error: undefined symbol: myFunction() Which (according to this Difference between string and char[] types in C++) is apparently due to std::string meaning different things in different versions of G++ and clang. Does this mean I have to rewrite the Makefile of my target library to use the same version of G++/Clang? Because that seems like an awful

Node.JS vm.runInNewContext() vs require() and eval()

大城市里の小女人 提交于 2019-12-13 11:43:26
问题 Is vm.runInNewContext considered black magic like eval ? Is there a significant performance difference between require and reading a file and using vm to run it or is the the same under the hood (if you implemented caching etc and just wanted to add some variables to the context) 回答1: runInNewContext is not meant to be used as a replacement of require or eval , but instead as a way to create a sandbox environment where you can safely run other scripts. Disadvantages are that it's slow

undefined reference when linking V8

人走茶凉 提交于 2019-12-13 05:27:51
问题 I'm strugling to compile a really small example with V8.. cpp program is this: #include "v8.h" int main() { v8::HandleScope handle_scope; return 0; } Compile line: g++ -I/home/lterje/git/tengine/Externals/v8/include /home/lterje/git/tengine/Externals/v8/out/ia32.release/obj.target/tools/gyp/libv8_snapshot.a test.cpp -o test -lpthread Error I'm getting: /tmp/ccHYtJuE.o: In function `main': test.cpp:(.text+0x11): undefined reference to `v8::HandleScope::HandleScope()' test.cpp:(.text+0x22):

Is it possible to use V8 in ASP?

﹥>﹥吖頭↗ 提交于 2019-12-13 04:00:38
问题 Since ASP (Active Server Pages) seems to be supported for at least 10 years, would it be possible to run ASP on V8? (Have anyone tried that?) (Note: I know that there is node.js or owin and advantages of these:) UPDATE: According to Wikipedia it also supports third party scripting languages for instance PerlScript. So, it seems to me that scripting layer is provided by a COM, therefore it might by possible to create COM wrapper for V8 that could be used in ASP. 回答1: As many people have said