Socket
Book a DemoInstallSign in
Socket

as-virtual

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

as-virtual

Virtual and reference data structures for AssemblyScript

latest
Source
npmnpm
Version
0.2.0
Version published
Maintainers
1
Created
Source

Virtual Type

The Virtual type is an efficient implementation for referencing segments of data without the need for constant memory allocations. This is particularly useful for tasks such as JSON parsing, where frequent slicing of strings can lead to high allocation rates. By using Virtual, you can reference memory segments directly, improving performance significantly. For example, this JSON implementation perviously parsed a Vec3 at 8,159,838m ops/s and with as-variant, it hit 39,260,740m ops/s.

Installation

npm install as-virtual

Usage

import { Virtual } from "as-virtual/assembly";

const virt = new Virtual<string>("foo bar", 3 << 1);
// Equiv. to "foo bar".slice(3)
// Note that we are referencing the memory directly and are using UTF-16

virt.equals("foo"); // true
virt.equals("baz"); // false

const virt2 = new Virtual<string>(" baz");
// Reinstantiate Virtual with new data
virt.reinst("bar", 6 << 1);

// Concat "bar" and " baz"
virt.merge(virt2);

console.log(virt.copyOut());

Keywords

assemblyscript

FAQs

Package last updated on 28 May 2024

Did you know?

Socket

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