Socket
Socket
Sign inDemoInstall

memory-pager

Package Overview
Dependencies
0
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    memory-pager

Access memory using small fixed sized buffers


Version published
Weekly downloads
3.3M
increased by2.11%
Maintainers
1
Install size
8.75 kB
Created
Weekly downloads
 

Package description

What is memory-pager?

The memory-pager package is a utility for managing and abstracting over pages of memory, allowing for efficient memory allocation and manipulation in a paged manner. It is particularly useful in scenarios where managing large datasets or buffers in a memory-efficient way is crucial, such as in databases or file systems.

What are memory-pager's main functionalities?

Page allocation and retrieval

This feature allows for the allocation and retrieval of memory pages. The code sample demonstrates how to allocate a new page (or retrieve it if it already exists) and then fill it with zeros.

const pager = require('memory-pager')();
let page = pager.get(0, true);
page.fill(0); // Allocate and fill the first page with zeros

Page updates and access

This feature enables updating and accessing data within a page. The code sample shows how to write data to a page and then read it back.

const data = Buffer.from('hello world');
page.set(data, 0); // Write data to the beginning of the page
const readData = page.get(0, data.length); // Read data from the page

Other packages similar to memory-pager

Readme

Source

memory-pager

Access memory using small fixed sized buffers instead of allocating a huge buffer. Useful if you are implementing sparse data structures (such as large bitfield).

travis

npm install memory-pager

Usage

var pager = require('paged-memory')

var pages = pager(1024) // use 1kb per page

var page = pages.get(10) // get page #10

console.log(page.offset) // 10240
console.log(page.buffer) // a blank 1kb buffer

API

var pages = pager(pageSize)

Create a new pager. pageSize defaults to 1024.

var page = pages.get(pageNumber, [noAllocate])

Get a page. The page will be allocated at first access.

Optionally you can set the noAllocate flag which will make the method return undefined if no page has been allocated already

A page looks like this

{
  offset: byteOffset,
  buffer: bufferWithPageSize
}
pages.set(pageNumber, buffer)

Explicitly set the buffer for a page.

pages.updated(page)

Mark a page as updated.

pages.lastUpdate()

Get the last page that was updated.

var buf = pages.toBuffer()

Concat all pages allocated pages into a single buffer

License

MIT

FAQs

Last updated on 09 Jan 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc