@stdlib/buffer-alloc-unsafe
v0.2.2
Published
Allocate a buffer having a specified number of bytes.
Downloads
3,830
Readme
allocUnsafe
Allocate a buffer having a specified number of bytes.
Installation
npm install @stdlib/buffer-alloc-unsafe
Usage
var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' );
allocUnsafe( size )
Unsafely allocates a buffer having a specified number of bytes.
var buf = allocUnsafe( 10 );
// returns <Buffer>
Notes
- 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.
Examples
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() );
}
See Also
@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.
Notice
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.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2024. The Stdlib Authors.