As you can read in the Node.js documentation on the Buffer class, a buffer
is similar to an array of integers but corresponds to a raw memory allocation outside the V8 heap.
So far, so good.
What now puzzles me is the question what a buffer is technically speaking. Is it an array with just some additional functions for creating and converting to strings using specific encodings?
Or is there "more" to it?
A buffer is a temporary memory that a stream takes to hold some data until it is consumed. In a stream, the buffer size is decided by the highWatermark property on the stream instance which is a number denoting the size of the buffer in bytes. A buffer memory in Node by default works on String and Buffer .
A buffer is an area of memory. Most JavaScript developers are much less familiar with this concept, compared to programmers using a system programming language (like C, C++, or Go), which interact directly with memory every day.
Buffers allocate raw memory outside the V8 heap. Buffer class is a global class so it can be used without importing the Buffer module in an application. Creating Buffers: Followings are the different ways to create buffers in Node. js: Create an uninitiated buffer: It creates the uninitiated buffer of given size.
No Buffering − Node. js applications never buffer any data. These applications simply output the data in chunks.
A Buffer is a chunk of memory, just like you would have it in C/C++. You can interpret this memory as an array of integer or floating point numbers of various lengths, or as a binary string. Unlike higher-level data structures like arrays, a buffer is not resizable.
It corresponds roughly to:
char*
or char[]
in C/C++byte[]
in Javabytes
or a non-resizable bytearray
in PythonBUFFER
is a temporary holding spot for data being moved from one place to another.
In order to understand what is Buffer, we need to know how a computer will process things. See the chart below.
The concept is like if you are watching a Youtube Video, you can start to watch a video without downloading the whole video. If your internet speed is too slow, you would see "buffering", that means the computer is trying to collect data in order for you to keep watching that video.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With