Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use shared memory in nodejs program?

I have some C++ services running on server and a node server program listening to a specific port. Can I use shared memory between C++ services and nodejs program? I want users to send data through nodejs server and those C++ services access them. Is it possible?

like image 548
JalalJaberi Avatar asked Feb 07 '13 01:02

JalalJaberi


People also ask

How do I allocate more memory to node js?

Luckily, the fix is fairly simple. Use the --max-old-space-size flag when running a Node. js application to increase the available memory heap. Note that the flag needs to come before calling the file with the node command.

How much memory can Nodejs use?

In Node < 12 , it sets a limit of 1.5 GB for long-lived objects by default. If this exceeds the memory available to your dyno, Node could allow your application to start paging memory to disk.

How does node js handle memory?

Memory Management in Node.Memory management provides ways to dynamically allocate memory chunks for programs when they request it, and free them when they are no longer needed – so that they can be reused. Application-level memory management can be manual or automatic.

What is the use of shared memory?

In computer science, shared memory is memory that may be simultaneously accessed by multiple programs with an intent to provide communication among them or avoid redundant copies. Shared memory is an efficient means of passing data between programs.


2 Answers

I tried write a C/C++ binding of shared memory access from nodejs. https://github.com/supipd/node-shm

Still work in progress (but working for me), maybe usefull, if bug or suggestion, inform me.

like image 103
supipd Avatar answered Sep 27 '22 23:09

supipd


You can write a binding to C/C++. Start from http://howtonode.org/how-to-module (Writing a Binding section).

Within the binding code, you can use shared memory to your C++ service, although it may make more sense to link directly to the service if it makes sense.

like image 43
Pascal Belloncle Avatar answered Sep 28 '22 01:09

Pascal Belloncle