-
Notifications
You must be signed in to change notification settings - Fork 30.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
doc: buffer.from will return internal pool buffer #24312
Conversation
ping @ChALkeR |
@ChALkeR can you please review this ? 😊 |
@ChALkeR I removed length condition from documentation. |
@nodejs/buffer @nodejs/documentation |
const nodeBuffers = Buffer.from([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); | ||
|
||
console.log(nodeBuffers.offset); | ||
// prints: 344 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not always correct. It may return 0, and any subsequent call will probably increase it.
So it doesn't always print 344.
// prints: 8192 | ||
|
||
// But you can change it | ||
Buffer.poolSize = 5; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be misleading. Changing Buffer.poolSize
does have immediate effect on which buffers would be pooled, but it doesn't immediately change the size of the current pool, it changes the size of the next pool.
It does, however, take immediate effect for determining whether should the buffer be allocated from the pool or not.
@mritunjaygoutam12 Sorry for delay on this, that was mostly due to my personal issues :-/. Overall, I don't think that the code example is very useful -- it's the confusing part atm, as it seems for me. Perhaps we can get this to land faster without the code example at all. As for the remaining part -- it specifically mentions E.g. these are not covered: > Buffer.from('sdf').offset
280
> Buffer.concat([Buffer.from('xxx'), Buffer.from('yyy')]).offset
304
> Buffer.from(Buffer.from('sdf')).offset
320
> Buffer.from(new String('test')).offset
328 The problem of the current documentation in master is that this section: Lines 100 to 103 in 17c6b1d
makes it seem that only .allocUnsafe is pooled, when in fact mostly everything is pooled.
Same for: Lines 597 to 609 in 17c6b1d
Perhaps some of the rewording should touch those? Also, /cc @nodejs/tsc @nodejs/buffer @nodejs/security-wg -- what was the reason for making |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some nits for consistency with other examples.
const nodeBuffers = Buffer.from([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); | ||
|
||
console.log(nodeBuffers.offset); | ||
// prints: 344 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// prints: 344 | |
// Prints: 344 |
|
||
// Default Buffer.poolsize is 8192 | ||
console.log(Buffer.poolSize); | ||
// prints: 8192 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// prints: 8192 | |
// Prints: 8192 |
const buf = Buffer.from([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); | ||
|
||
console.log(buf.offset); | ||
// prints: 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// prints: 0 | |
// Prints: 0 |
@mritunjayz - can you address the review comments? |
@mritunjayz, are you still interested in working on the PR ? If not, let me know; I can pick this up and progress. |
@HarshithaKP yes, you can. Thanks |
This can be closed as the intention is fulfilled in #32703. |
Checklist
#22139
Buffer.from will also use internal
Buffer
pool if it's size is less thenBuffer.poolSize
.