{"action":"created","issue":{"url":"https://api.github.com/repos/nodejs/node/issues/4682","labels_url":"https://api.github.com/repos/nodejs/node/issues/4682/labels{/name}","comments_url":"https://api.github.com/repos/nodejs/node/issues/4682/comments","events_url":"https://api.github.com/repos/nodejs/node/issues/4682/events","html_url":"https://github.com/nodejs/node/pull/4682","id":126574513,"number":4682,"title":"buffer: add Buffer.safe() and Buffer.unsafe(), deprecate Buffer(num)","user":{"login":"jasnell","id":439929,"avatar_url":"https://avatars.githubusercontent.com/u/439929?v=3","gravatar_id":"","url":"https://api.github.com/users/jasnell","html_url":"https://github.com/jasnell","followers_url":"https://api.github.com/users/jasnell/followers","following_url":"https://api.github.com/users/jasnell/following{/other_user}","gists_url":"https://api.github.com/users/jasnell/gists{/gist_id}","starred_url":"https://api.github.com/users/jasnell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jasnell/subscriptions","organizations_url":"https://api.github.com/users/jasnell/orgs","repos_url":"https://api.github.com/users/jasnell/repos","events_url":"https://api.github.com/users/jasnell/events{/privacy}","received_events_url":"https://api.github.com/users/jasnell/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/nodejs/node/labels/buffer","name":"buffer","color":"f7c6c7"},{"url":"https://api.github.com/repos/nodejs/node/labels/in%20progress","name":"in progress","color":"ededed"},{"url":"https://api.github.com/repos/nodejs/node/labels/semver-major","name":"semver-major","color":"fbca04"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":16,"created_at":"2016-01-14T04:23:32Z","updated_at":"2016-01-14T18:03:30Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/nodejs/node/pulls/4682","html_url":"https://github.com/nodejs/node/pull/4682","diff_url":"https://github.com/nodejs/node/pull/4682.diff","patch_url":"https://github.com/nodejs/node/pull/4682.patch"},"body":"This is currently a work in progress for discussion purposes. Please do not land!\r\n\r\nPer the discussion in https://github.com/nodejs/node/issues/4660, this adds `Buffer.safe()` and `Buffer.unsafe()` and deprecates `Buffer(num)`. Every existing call to `Buffer(num)` in the tests is modified to use `Buffer.unsafe()` except for one intentionally left to cover the `Buffer(num, enc)` error case.\r\n\r\n`Buffer.unsafe()` uses the same implementation as `Buffer(num)` (with slightly modified input arg verification) which uses slab allocation to allocate non-zero filled Buffers as efficiently as possible.\r\n\r\n`Buffer.safe()` does not use the slab and calls `createBuffer(num)` to create a brand new zero-filled Buffer. This means that *every* call to `Buffer.safe()` will result in a `calloc` making it far more expensive than `Buffer.unsafe()`. It is, however, safer :-)"},"comment":{"url":"https://api.github.com/repos/nodejs/node/issues/comments/171724233","html_url":"https://github.com/nodejs/node/pull/4682#issuecomment-171724233","issue_url":"https://api.github.com/repos/nodejs/node/issues/4682","id":171724233,"user":{"login":"Fishrock123","id":1093990,"avatar_url":"https://avatars.githubusercontent.com/u/1093990?v=3","gravatar_id":"","url":"https://api.github.com/users/Fishrock123","html_url":"https://github.com/Fishrock123","followers_url":"https://api.github.com/users/Fishrock123/followers","following_url":"https://api.github.com/users/Fishrock123/following{/other_user}","gists_url":"https://api.github.com/users/Fishrock123/gists{/gist_id}","starred_url":"https://api.github.com/users/Fishrock123/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Fishrock123/subscriptions","organizations_url":"https://api.github.com/users/Fishrock123/orgs","repos_url":"https://api.github.com/users/Fishrock123/repos","events_url":"https://api.github.com/users/Fishrock123/events{/privacy}","received_events_url":"https://api.github.com/users/Fishrock123/received_events","type":"User","site_admin":false},"created_at":"2016-01-14T18:03:30Z","updated_at":"2016-01-14T18:03:30Z","body":"This is moving a bit quick, but some general things:\r\n\r\n1. If we are going to do this, `Buffer(number)` should be deprecated, probably first only in docs. I prefer runtime deprecations, since you can ignore them `--no-deprecation`, but I understand some users don't.\r\n2. `safe()` and `unsafe()` are not actually that descriptive. These sound like you are truning something on or off. I suggest going for `allocSafe()` and `allocUnsafe()`.\r\n3. `--zero-fill-buffers` is a better naming, yes.\r\n\r\nYou mentioned the pooling aspect. Would it be worthwhile to have a safe pool, or does that defeat the purpose?\r\n\r\n@jasnell Could you make sure to split up these commits, one replacing usage in core should be separate as it is quite large and makes this difficult to review."}}