Allocate a buffer having a specified number of bytes.
npm install @stdlib/buffer-alloc-unsafe
Alternatively,
- To load the package in a website via a
script
tag without installation and bundlers, use the ES Module available on theesm
branch. - If you are using Deno, visit the
deno
branch. - For use in Observable, or in browser/node environments, use the Universal Module Definition (UMD) build available on the
umd
branch.
The branches.md file summarizes the available branches and displays a diagram illustrating their relationships.
var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' );
Unsafely allocates a buffer having a specified number of bytes.
var buf = allocUnsafe( 10 );
// returns <Buffer>
- The underlying memory of returned
Buffer
instances is not initialized. Memory contents are unknown and may contain sensitive data. - When the
size
is less than half the pool size (specified on theBuffer
constructor in modern Node.js environments), memory is allocated from theBuffer
pool for faster allocation of newBuffer
instances.
var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' );
var buf;
var i;
// Repeatedly unsafely allocate memory and inspect the buffer contents...
for ( i = 0; i < 100; i++ ) {
buf = allocUnsafe( 100 );
console.log( buf.toString() );
}
@stdlib/buffer-ctor
: Buffer.@stdlib/buffer-from-array
: allocate a buffer using an octet array.@stdlib/buffer-from-arraybuffer
: allocate a buffer from an ArrayBuffer.@stdlib/buffer-from-buffer
: copy buffer data to a new Buffer instance.@stdlib/buffer-from-string
: allocate a buffer containing a provided string.
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
See LICENSE.
Copyright © 2016-2023. The Stdlib Authors.