Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • NodeJS Tutorial
  • NodeJS Exercises
  • NodeJS Assert
  • NodeJS Buffer
  • NodeJS Console
  • NodeJS Crypto
  • NodeJS DNS
  • NodeJS File System
  • NodeJS Globals
  • NodeJS HTTP
  • NodeJS HTTP2
  • NodeJS OS
  • NodeJS Path
  • NodeJS Process
  • NodeJS Query String
  • NodeJS Stream
  • NodeJS String Decoder
  • NodeJS Timers
  • NodeJS URL
  • NodeJS Interview Questions
  • NodeJS Questions
  • Web Technology
Open In App
Next Article:
Node.js Buffer.copy() Method
Next article icon

Node.js Buffer.allocUnsafe() Method

Last Updated : 13 Oct, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report
The Buffer.allocUnsafe() method is an inbuilt application programming interface of class Buffer with in Buffer module which is used to allocate the buffer of given size but not initialize it. Syntax:
const Buffer.allocUnsafe( size)
Parameters: This method accepts a single parameter size which holds the desired size of the buffer. Return value: It allocates the buffer of the given size. Below examples illustrate the use of Buffer.allocUnsafe() Method in Node.js: Example 1: javascript
// Node program to demonstrate the  // Buffer.allocUnsafe(size) method    // Creating a buffer of given size const buf = Buffer.allocUnsafe(10);    // Display the result console.log("10 size Buffer created"); console.log(buf); 
Output:
  10 size Buffer created  <Buffer 88 c4 62 ba 48 02 00 00 a8 c5>  
Example 2: javascript
// Node program to demonstrate the  // Buffer.allocUnsafe(size) method    // Creating a buffer of given size const buf = Buffer.allocUnsafe(10);   // Display the result console.log("Before filling the Buffer"); console.log(buf);   // Fill buffer with element 'G' buf.fill('G');    // Display the result console.log("After filling Buffer"); console.log(buf); 
Output:
Before filling the Buffer    After filling Buffer  
Note: The above program will compile and run by using the node myapp.js command. Reference: https://nodejs.org/dist/latest-v13.x/docs/api/buffer.html#buffer_class_method_buffer_allocunsafe_size

Next Article
Node.js Buffer.copy() Method

R

RohitPrasad3
Improve
Article Tags :
  • Web Technologies
  • Node.js
  • NodeJS-function

Similar Reads

  • Node.js Buffer.alloc() Method
    The Buffer.alloc() method is used to create a new buffer object of the specified size. This method is slower than Buffer.allocUnsafe() method but it assures that the newly created Buffer instances will never contain old information or data that is potentially sensitive. Syntax Buffer.alloc(size, fil
    2 min read
  • Node.js Buffer.isBuffer() Method
    Buffer is a temporary memory storage that stores the data when it is being moved from one place to another. It is like an array of integers.  The Buffer.isBuffer() method checks whether the provided object is a buffer or not.  Syntax: Buffer.isBuffer( obj ) Parameters: This method accepts a single p
    2 min read
  • Node.js Buffer.fill() Method
    Buffer is a temporary memory storage that stores the data when it is being moved from one place to another. It's like an array of integers. The Buffer.fill() Method puts the data into the buffer instance. If the offset and end values are not given then the complete buffer will be filled.  Syntax: bu
    2 min read
  • Node.js Buffer.from() Method
    The Buffer.from() method is used to create a new buffer containing the specified string, array, or buffer.  Syntax: Buffer.from( object, encoding ) Parameters: This method accepts two parameters as mentioned above and described below: object: This parameter can hold either a string, buffer, array, o
    2 min read
  • Node.js Buffer.copy() Method
    Buffer is a temporary memory storage that stores the data when it is being moved from one place to another. It is like an array of integers. The Buffer.copy() method simply copies all the values from the input buffer to another buffer. Syntax: buffer.copy( target, targetStart, sourceStart, sourceEnd
    2 min read
  • Node.js Buffer.keys() Method
    The Buffer.keys() method is used to return an iterator object, containing the key of every byte in a buffer object.  Syntax: Buffer.keys() Parameters: This method does not accept any parameters.  Return Value: It returns an iterator object having the keys of the buffer.  Example 1: In this example,
    1 min read
  • Node.js Buffer.write() Method
    The Buffer.write() method writes the specified string into a buffer, at the specified position. If buffer did not contain enough space to fit the entire string, only part of string will be written. However, partially encoded characters will not be written. Syntax: buffer.write( string, offset, lengt
    2 min read
  • Node.js Buffer.slice() Method
    Buffer is a temporary memory storage that stores the data when it is being moved from one place to another, it's like an array of integers.  The Buffer.slice() method returns a new Buffer that points to the same memory location as that of the input Buffer with only the cropped elements.  Syntax: buf
    2 min read
  • Node.js fs.closeSync() Method
    The fs.closeSync() method is used to synchronously close the given file descriptor thereby clearing the file that is associated with it. It allows the file descriptor to be reused for other files. Calling fs.closeSync() on a file descriptor while some other operation is being performed on it may lea
    2 min read
  • Node.js Buffer.toJSON() Method
    Buffer is a temporary memory storage which stores the data when it is being moved from one place to another. It is like the array of integers. The Buffer.toJSON() method returns the buffer in JSON format. Note: The JSON.Stringify() is the method which can also be used to return the data in JSON form
    1 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences