GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Some questions about buffer doc · Issue #9786 · nodejs/node Closed Description
I'm preparing a PR with some small fixes in code examples of the buffer doc and I've stumbled on some puzzles I want to clarify before the PR.
What does the "(not inclusive)" remark actually mean? In this code (not in the doc) the console.log(Buffer.from('0123').lastIndexOf('1', 1)); The same for this code in the doc: Buffer.from('this buffer is a buffer'); // Prints: 5 console.log(buf.lastIndexOf('buffer', 5)); So the question is this one: should this remark be clarified more or should it be removed?
It happens that the actual outputs of these fragments do not match with described ones for me for most of the tests: const buf = new Buffer(5); // Prints: (contents may vary): <Buffer 78 e0 82 02 01> console.log(buf); buf.fill(0); // Prints: <Buffer 00 00 00 00 00> console.log(buf); const buf = Buffer.allocUnsafe(5); // Prints: (contents may vary): <Buffer 78 e0 82 02 01> console.log(buf); buf.fill(0); // Prints: <Buffer 00 00 00 00 00> console.log(buf); While they do output as described in the REPL, tested by script files they output the same lines in some circumstances: After some research, I've found out there is a rather strong correlation between script file size and zeroing of a buffer beginning. If the before mentioned fragments are saved in 105-176 bytes file size (adjusted by these changes: ASCII/UTF-8, +/- BOM, +/- comments/space), the first 5 bytes are almost always empty. So I've written a weird script to find out more about this correlation. Here are some notes about results: a. Zeroing scheme of buffer bytes is the same inside cycles of a script file size increasing by 8 bytes. If somebody is interested in the research code, here is the script. In the comments there, I also give the stat data from a test run on my machine. The stat data format is "script file size: scheme with non-zero bytes indexes in created buffers". Repeated lines inside 8-bytes cycles are filtered. If some flaky case happens inside this cycles, it is marked by So the question is this one: is this correlation depends on some hardware/software features or is it something stable? In the first case, it could be ignored, in the second case the code examples should be adjusted to fall out of size diapasons that produce big zero fragments at the beginning or buffers, otherwise, novices could be confused by these examples if they run them by themselves. Sorry for my bad English and all the possible obscurity. Activity
MetadataMetadataAssigneesLabelsTypeProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402775 — 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. |