阿西河

所有教程

公众号
🌙
阿西河前端的公众号

我的收藏

    最近访问  (文章)

      教程列表

      抓包专区
      测试专区

      Node.js Buffer SlowBuffer 类(废弃)

      Node.js Buffer SlowBuffer 类(废弃) 废弃于: v6.0.0

      Returns an un-pooled Buffer.

      In order to avoid the garbage collection overhead of creating many individually allocated Buffer instances, by default allocations under 4KB are sliced from a single larger allocated object.

      In the case where a developer may need to retain a small chunk of memory from a pool for an indeterminate amount of time, it may be appropriate to create an un-pooled Buffer instance using SlowBuffer then copy out the relevant bits.

      // Need to keep around a few small chunks of memory
      const store = [];
      
      socket.on('readable', () => {
        const data = socket.read();
      
        // Allocate for retained data
        const sb = SlowBuffer(10);
      
        // Copy the data into the new allocation
        data.copy(sb, 0, 0, 10);
      
        store.push(sb);
      });
      

      Use of SlowBuffer should be used only as a last resort after a developer has observed undue memory retention in their applications.


      更多内容请参考:Node.js Buffer 缓冲器,或者通过 点击对应菜单 进行查看;


      目录
      本文目录
      目录