npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nd-shmem

v1.0.12

Published

nd-shmem ======================= - simple binding of shmget shmat shmdt shmctl

Downloads

7

Readme

nd-shmem

  • simple binding of shmget shmat shmdt shmctl

  • only work in nodejs

  • for fast copy json-buffer/v8-serde using

  • suitable for one writer(server) , many readers(client)

  • it has no sync-mechanism implemented, you need do it yourself(normally just use socket/signal is OK)

install

  • npm install nd-shmem

usage

  const x   = require("nd-shmem");

example

server

			Welcome to Node.js v20.1.0.
			Type ".help" for more information.
			>

			const x1 = require("nd-shmem");
			/*
			> x1.pid_
			470134
			>
			*/
			

			var mgmt = x1.creat_shmem_mgmt("shmem5g",1024*1024*1024*5);  // alloc a 5G shared buffer

			/*
			ShmemMgmt {
			  shmid: 12,
			  maxsz: 5368709120n,
			  pathname: '/home/cu-lib/nd-shmem/TEST/shmem5g',
			  proj_id: 65
			}

			> x1._eng.get_maxsz_with_shmid(12)
			[ true, 5368709120n ]
			>
			*/

clinet A

			Welcome to Node.js v20.1.0.
			Type ".help" for more information.
			>

			const x2 = require("nd-shmem");

			/*
			> x2.pid_
			470282
			>
			*/

			var vw_0to1g = x2.creat_view(12,1024*1024*1024,0)
			vw_0to1g[10]=255

			/*
			> vw_0to1g.buffer
			ArrayBuffer {
			  [Uint8Contents]: <00 00 00 00 00 00 00 00 00 00 【ff】 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ... 1073741724 more bytes>,
			  byteLength: 1073741824
			}
			>
			*/

client B

			Welcome to Node.js v20.1.0.
			Type ".help" for more information.
			>

			const x3 = require("nd-shmem");

			/*
			> x3.pid_
			470428
			>
			*/

			var vw_10to2g = x3.creat_view(12,1024*1024*1024*2,10)

			/*
			> vw_10to2g.buffer
			ArrayBuffer {
			  [Uint8Contents]: <【ff】 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ... 2147483548 more bytes>,
			  byteLength: 2147483648
			}
			>
			>
			*/
			vw_10to2g.set(Buffer.from(JSON.stringify([10,20,30])),5);

			> vw_10to2g.buffer
			ArrayBuffer {
			  [Uint8Contents]: <【ff】 00 00 00 00 【5b 31 30 2c 32 30 2c 33 30 5d】 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ... 2147483548 more bytes>,
			  byteLength: 2147483648
			}
			>



			//GO BACK  TO PROCESS X2 :

			/*
			> x2.pid_
			470282
			>
			*/
			vw_0to1g.subarray(10+5,10+5+10)
			/*
			>
			Shmem(10) [Uint8Array] [
			  91,
			  49,
			  48,
			  44,
			  50,
			  48,
			  44,
			  51,
			  48,
			  93,
			  shmid: -1,
			  state: 0,
			  shm_offset: -1
			]
			>

			> Buffer.from(vw_0to1g.subarray(10+5,10+5+10)).toString()
			'[10,20,30]'
			>

			*/


			/*

ipcs

			------ Message Queues --------
			key        msqid      owner      perms      used-bytes   messages

			------ Shared Memory Segments --------
			key        shmid      owner      perms      bytes      nattch     status
			0x00000000 12         root       0          5368709120 3          dest

			------ Semaphore Arrays --------
			key        semid      owner      perms      nsems
			*/

METHODS

ShmemMgmt

        mgmt.creat_view(sz:<must le 4G, else ArrayBuffer detached>,  offset=0) -> Shmem   // offset  alloc-the-array-buffer-backing-store-from-shmem
		mgmt.destroy()  -> [ Boolean, <shmid> ]                                           // shmctl(shmid,IPC_RMID,NULL);
		//getter dont change them , else crash
		mgmt.shmid
		mgmt.maxsz
		mgmt.pathname
		mgmt.proj_id

Shmem

        Shmem is just a Uint8Array


		detach()       ->  [ Boolean, <u64ptr> ]             //shmdt
		is_detached()
		is_active()
		//getter dont changethem, else crash
		shmem.shmid
		shmem.state
		shmem.shm_offset

APIS

###on mgmt:
maxsz is a BigInt, must <= os.freemem())

  const  creat_shmem_mgmt               = (pathname='shmem',maxsz=1024n*1024n*1024n,proj_id=65) => new ShmemMgmt({pathname,proj_id,maxsz,force:_f});
  const  creat_shmem_mgmt_force         = (pathname='shmem',maxsz=1024n*1024n*1024n,proj_id=65) => new ShmemMgmt({pathname,proj_id,maxsz,force:_t});

on client:

   creat_view(shmid,sz:<must le 4G, else ArrayBuffer detached>, offset=0) -> Shmem

LICENSE

  • ISC