GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — buffer: use smalloc as backing data store · tcper/node@3a2f273

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • doc/api
    • buffer.markdown
  • lib
    • buffer.js
  • src
    • node.js
    • node_buffer.cc
    • node_buffer.h
    • node_crypto.cc
    • node_internals.h
    • slab_allocator.cc
    • string_bytes.cc
    • tls_wrap.cc
  • test/simple
    • test-buffer-regress-GH-2659.js
    • test-buffer.js
    • test-readdouble.js
    • test-readfloat.js
    • test-readint.js
    • test-readuint.js
    • test-writedouble.js
    • test-writefloat.js
    • test-writeint.js
    • test-writeuint.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/buffer.markdown‎

Copy file name to clipboardExpand all lines: doc/api/buffer.markdown
+65-68Lines changed: 65 additions & 68 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,69 @@ Allocates a new buffer containing the given `str`.
8080
Returns true if the `encoding` is a valid encoding argument, or false
8181
otherwise.
8282

83+
### Class Method: Buffer.isBuffer(obj)
84+
85+
* `obj` Object
86+
* Return: Boolean
87+
88+
Tests if `obj` is a `Buffer`.
89+
90+
### Class Method: Buffer.byteLength(string, [encoding])
91+
92+
* `string` String
93+
* `encoding` String, Optional, Default: 'utf8'
94+
* Return: Number
95+
96+
Gives the actual byte length of a string. `encoding` defaults to `'utf8'`.
97+
This is not the same as `String.prototype.length` since that returns the
98+
number of *characters* in a string.
99+
100+
Example:
101+
102+
str = '\u00bd + \u00bc = \u00be';
103+
104+
console.log(str + ": " + str.length + " characters, " +
105+
Buffer.byteLength(str, 'utf8') + " bytes");
106+
107+
// ½ + ¼ = ¾: 9 characters, 12 bytes
108+
109+
### Class Method: Buffer.concat(list, [totalLength])
110+
111+
* `list` {Array} List of Buffer objects to concat
112+
* `totalLength` {Number} Total length of the buffers when concatenated
113+
114+
Returns a buffer which is the result of concatenating all the buffers in
115+
the list together.
116+
117+
If the list has no items, or if the totalLength is 0, then it returns a
118+
zero-length buffer.
119+
120+
If the list has exactly one item, then the first item of the list is
121+
returned.
122+
123+
If the list has more than one item, then a new Buffer is created.
124+
125+
If totalLength is not provided, it is read from the buffers in the list.
126+
However, this adds an additional loop to the function, so it is faster
127+
to provide the length explicitly.
128+
129+
### buf.length
130+
131+
* Number
132+
133+
The size of the buffer in bytes. Note that this is not necessarily the size
134+
of the contents. `length` refers to the amount of memory allocated for the
135+
buffer object. It does not change when the contents of the buffer are changed.
136+
137+
buf = new Buffer(1234);
138+
139+
console.log(buf.length);
140+
buf.write("some string", 0, "ascii");
141+
console.log(buf.length);
142+
143+
// 1234
144+
// 1234
145+
83146
### buf.write(string, [offset], [length], [encoding])
84147

85148
* `string` String - data to be written to buffer
@@ -155,69 +218,6 @@ Example: copy an ASCII string into a buffer, one byte at a time:
155218

156219
// node.js
157220

158-
### Class Method: Buffer.isBuffer(obj)
159-
160-
* `obj` Object
161-
* Return: Boolean
162-
163-
Tests if `obj` is a `Buffer`.
164-
165-
### Class Method: Buffer.byteLength(string, [encoding])
166-
167-
* `string` String
168-
* `encoding` String, Optional, Default: 'utf8'
169-
* Return: Number
170-
171-
Gives the actual byte length of a string. `encoding` defaults to `'utf8'`.
172-
This is not the same as `String.prototype.length` since that returns the
173-
number of *characters* in a string.
174-
175-
Example:
176-
177-
str = '\u00bd + \u00bc = \u00be';
178-
179-
console.log(str + ": " + str.length + " characters, " +
180-
Buffer.byteLength(str, 'utf8') + " bytes");
181-
182-
// ½ + ¼ = ¾: 9 characters, 12 bytes
183-
184-
### Class Method: Buffer.concat(list, [totalLength])
185-
186-
* `list` {Array} List of Buffer objects to concat
187-
* `totalLength` {Number} Total length of the buffers when concatenated
188-
189-
Returns a buffer which is the result of concatenating all the buffers in
190-
the list together.
191-
192-
If the list has no items, or if the totalLength is 0, then it returns a
193-
zero-length buffer.
194-
195-
If the list has exactly one item, then the first item of the list is
196-
returned.
197-
198-
If the list has more than one item, then a new Buffer is created.
199-
200-
If totalLength is not provided, it is read from the buffers in the list.
201-
However, this adds an additional loop to the function, so it is faster
202-
to provide the length explicitly.
203-
204-
### buf.length
205-
206-
* Number
207-
208-
The size of the buffer in bytes. Note that this is not necessarily the size
209-
of the contents. `length` refers to the amount of memory allocated for the
210-
buffer object. It does not change when the contents of the buffer are changed.
211-
212-
buf = new Buffer(1234);
213-
214-
console.log(buf.length);
215-
buf.write("some string", 0, "ascii");
216-
console.log(buf.length);
217-
218-
// 1234
219-
// 1234
220-
221221
### buf.copy(targetBuffer, [targetStart], [sourceStart], [sourceEnd])
222222

223223
* `targetBuffer` Buffer object - Buffer to copy into
@@ -694,11 +694,8 @@ Note that this is a property on the buffer module returned by
694694

695695
## Class: SlowBuffer
696696

697-
This class is primarily for internal use. JavaScript programs should
698-
use Buffer instead of using SlowBuffer.
697+
Deprecated. SlowBuffer now returns an instance of Buffer.
699698

700699
In order to avoid the overhead of allocating many C++ Buffer objects for
701700
small blocks of memory in the lifetime of a server, Node allocates memory
702-
in 8Kb (8192 byte) chunks. If a buffer is smaller than this size, then it
703-
will be backed by a parent SlowBuffer object. If it is larger than this,
704-
then Node will allocate a SlowBuffer slab for it directly.
701+
in 8Kb (8192 byte) chunks. This is now handled by Smalloc.

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.