Node.js中的缓冲区是什么? [英] What is a buffer in Node.js?

查看:79
本文介绍了Node.js中的缓冲区是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以阅读有关Buffer类的Node.js文档,即一个缓冲区


类似于整数数组,但对应于V8堆之外的原始内存分配。


到目前为止,还不错。



现在让我感到困惑的是,从技术上讲缓冲是个问题。



是它的数组吗?

$ b $还是有更多的函数?



b

解决方案

缓冲区是一块内存,就像在C / C ++中一样。您可以将此内存解释为各种长度的整数或浮点数的数组,也可以解释为二进制字符串。与数组等高级数据结构不同,缓冲区不可调整大小。



它大致对应于:




  • char * char [] 在C / C ++中

  • byte [] in Java

  • 可变的 bytes 或Python中不可调整大小的 bytearray

  • 如果可变,则是php中的字符串


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 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 Java
  • A mutable bytes or a non-resizable bytearray in Python
  • Strings in php if they were mutable

这篇关于Node.js中的缓冲区是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆