Buffer is a temporary memory storage which stores the data when it is being moved from one place to another. It’s like the array of integers. Buffer.allocUnsafeSlow() Method allocates a new buffer instance of given size but do not initialize it.
The Buffer.allocUnsafeSlow() method is used to allocate a new Buffer of given size in bytes. If the given size is greater than buffer.constants.MAX_LENGTH or less than 0, ERR_INVALID_OPT_VALUE is thrown. If the size is zero then a zero-length Buffer is created.
This method is different from Buffer.allocUnsafe() method. In allocUnsafe() method, if buffer size is less than 4KB than it automatically cut out the required buffer from a pre-allocated buffer i.e. it does not initialize a new buffer. It saves memory by not allocating many small Buffer instances. But if developer need to hold on some amount of overhead memory for intermediate amount of time, than allocUnsafeSlow() method can be used.
buffer.allocUnsafeSlow( size )
Parameters: This method accepts single parameter size which holds the desired size of the buffer.
Note: This method throws a TypeError if size is not a number.
Below examples illustrate the use of Buffer.allocUnsafeSlow() Method in Node.js:
allocUnsafeSlow() Method <Buffer 01 00 00 00 00 00 00 00 8b ed>
Note: The above program will compile and run by using the
node index.js command.
- Nodejs | Automatic restart NodeJs server with nodemon
- Nodejs | DNS
- Nodejs | DNS | setServers()
- Nodejs | Jimp
- Web-Socket in NodeJS
- Dockerizing a simple Nodejs app
- Difference between NodeJS and AngularJS
- Encrypting Data in NodeJS
- Nodejs | Web Crawling using Cheerio
- Nodejs | GM charcoal() Function
- Nodejs | GM blur() Function
- Nodejs | GM sharpen() Function
- Signup Form Using Nodejs and MongoDB
- Cowsay in Nodejs using Requests library
- Nodejs – Connect Mysql with Node app
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.