node.js插件与child_process的优点 [英] Advantages of node.js addon vs child_process

查看:58
本文介绍了node.js插件与child_process的优点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与通过child_process调用带有参数的二进制文件相比,使用C / C ++编写的node.js插件有什么好处(如果有)?

What would be the advantages, if any, of using a node.js addon written in C/C++ compared to calling a binary with arguments through child_process?

更具体地说,我有一个小程序,该程序最多可以接受数百个参数并返回布尔值。

More specifically, I have a small program, which accepts possibly up to a few hundred arguments and returns a boolean.

推荐答案

有很大的不同。

C ++插件是作为主应用程序的一部分运行的本机代码(与JS处于同一级别)。但是,如果使用 child_process ,则节点将启动新进程,并且会产生巨大的开销(生成进程比在一个线程中运行本机代码要复杂得多)。

C++ Addon is native code which is running as part of main application (on the same level as JS does). But if you use child_process, node will start new process and there is a huge overhead (spawning processes is much more complicated than running native code in one thread).

如果您决定使用哪种方法,则很大程度上取决于您的情况。如果您熟悉C ++并且想要处理成千上万的请求,则可能应该考虑编写插件。但是,如果您正在编写供个人使用的小型应用程序,并且您的其他程序已经可以作为独立应用程序使用,那么我将使用child_process,它也可以以较少的工作量提供出色的结果。

If you are deciding, which approach to use, it heavily depends on your situation. If you are familiar with C++ and you want to handle thousands of requests, you probably should consider writing an addon. But if you are writing a small app for personal use and your additional program is already functional as stand-alone app, I would use child_process and it can also provide great results with less effort.

这篇关于node.js插件与child_process的优点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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