{"action":"created","comment":{"url":"https://api.github.com/repos/dotnet/corefxlab/pulls/comments/42814632","id":42814632,"diff_hunk":"@@ -0,0 +1,76 @@\n+// Copyright (c) Microsoft. All rights reserved.\n+// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n+\n+using System;\n+using System.Diagnostics;\n+using System.Threading;\n+\n+namespace System.Buffers\n+{\n+    internal sealed class BufferBucket\n+    {\n+        private volatile int _index;\n+        private byte[][] _data;\n+        private int _bufferSize;\n+        private SpinLock _lock;\n+\n+        internal BufferBucket(int bufferSize, int numberOfBuffers)\n+        {\n+            _index = 0;\n+            _bufferSize = bufferSize;\n+            _lock = new SpinLock();\n+            _data = new byte[numberOfBuffers][];\n+            for (int i = 0; i < numberOfBuffers; i++)\n+            {\n+                _data[i] = new byte[bufferSize];\n+            }\n+        }\n+\n+        internal BufferData Rent()\n+        {\n+            BufferData bd = new BufferData() { _data = null };\n+\n+            // Be quick and do an unsynchronized read to see if all\n+            // of our buffers have been used\n+            if (_index + 1>= _data.Length)\n+            {\n+                bd._data = new byte[_bufferSize];\n+                bd._allocd = true;\n+            }\n+            else\n+            {\n+                // Use a SpinLock since it is super lightweight\n+                // and our lock is very short lived\n+                bool taken = false;\n+                _lock.Enter(ref taken);\n+                Debug.Assert(taken);\n+\n+                bd._data = _data[_index];","path":"src/System.Buffers/src/System/Buffers/BufferBucket.cs","position":48,"original_position":48,"commit_id":"f9dc2b94fe65367c81685404770e3a386790d58c","original_commit_id":"f9dc2b94fe65367c81685404770e3a386790d58c","user":{"login":"sokket","id":1761798,"avatar_url":"https://avatars.githubusercontent.com/u/1761798?v=3","gravatar_id":"","url":"https://api.github.com/users/sokket","html_url":"https://github.com/sokket","followers_url":"https://api.github.com/users/sokket/followers","following_url":"https://api.github.com/users/sokket/following{/other_user}","gists_url":"https://api.github.com/users/sokket/gists{/gist_id}","starred_url":"https://api.github.com/users/sokket/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sokket/subscriptions","organizations_url":"https://api.github.com/users/sokket/orgs","repos_url":"https://api.github.com/users/sokket/repos","events_url":"https://api.github.com/users/sokket/events{/privacy}","received_events_url":"https://api.github.com/users/sokket/received_events","type":"User","site_admin":false},"body":"Good catch, thanks...fixing now","created_at":"2015-10-22T22:28:32Z","updated_at":"2015-10-22T22:28:32Z","html_url":"https://github.com/dotnet/corefxlab/pull/353#discussion_r42814632","pull_request_url":"https://api.github.com/repos/dotnet/corefxlab/pulls/353","_links":{"self":{"href":"https://api.github.com/repos/dotnet/corefxlab/pulls/comments/42814632"},"html":{"href":"https://github.com/dotnet/corefxlab/pull/353#discussion_r42814632"},"pull_request":{"href":"https://api.github.com/repos/dotnet/corefxlab/pulls/353"}}},"pull_request":{"url":"https://api.github.com/repos/dotnet/corefxlab/pulls/353","id":48516408,"html_url":"https://github.com/dotnet/corefxlab/pull/353","diff_url":"https://github.com/dotnet/corefxlab/pull/353.diff","patch_url":"https://github.com/dotnet/corefxlab/pull/353.patch","issue_url":"https://api.github.com/repos/dotnet/corefxlab/issues/353","number":353,"state":"open","locked":false,"title":"Adding initial, prototype implementation for a ByteBufferPool","user":{"login":"sokket","id":1761798,"avatar_url":"https://avatars.githubusercontent.com/u/1761798?v=3","gravatar_id":"","url":"https://api.github.com/users/sokket","html_url":"https://github.com/sokket","followers_url":"https://api.github.com/users/sokket/followers","following_url":"https://api.github.com/users/sokket/following{/other_user}","gists_url":"https://api.github.com/users/sokket/gists{/gist_id}","starred_url":"https://api.github.com/users/sokket/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sokket/subscriptions","organizations_url":"https://api.github.com/users/sokket/orgs","repos_url":"https://api.github.com/users/sokket/repos","events_url":"https://api.github.com/users/sokket/events{/privacy}","received_events_url":"https://api.github.com/users/sokket/received_events","type":"User","site_admin":false},"body":"Adding initial, prototype implementation for a ByteBufferPool.\r\n\r\n/cc @KrzysztofCwalina ","created_at":"2015-10-22T21:36:35Z","updated_at":"2015-10-22T22:28:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"73f2e0dc82c01b24209d4b4e216a1f0b07a3312e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/dotnet/corefxlab/pulls/353/commits","review_comments_url":"https://api.github.com/repos/dotnet/corefxlab/pulls/353/comments","review_comment_url":"https://api.github.com/repos/dotnet/corefxlab/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dotnet/corefxlab/issues/353/comments","statuses_url":"https://api.github.com/repos/dotnet/corefxlab/statuses/f9dc2b94fe65367c81685404770e3a386790d58c","head":{"label":"sokket:buffers","ref":"buffers","sha":"f9dc2b94fe65367c81685404770e3a386790d58c","user":{"login":"sokket","id":1761798,"avatar_url":"https://avatars.githubusercontent.com/u/1761798?v=3","gravatar_id":"","url":"https://api.github.com/users/sokket","html_url":"https://github.com/sokket","followers_url":"https://api.github.com/users/sokket/followers","following_url":"https://api.github.com/users/sokket/following{/other_user}","gists_url":"https://api.github.com/users/sokket/gists{/gist_id}","starred_url":"https://api.github.com/users/sokket/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sokket/subscriptions","organizations_url":"https://api.github.com/users/sokket/orgs","repos_url":"https://api.github.com/users/sokket/repos","events_url":"https://api.github.com/users/sokket/events{/privacy}","received_events_url":"https://api.github.com/users/sokket/received_events","type":"User","site_admin":false},"repo":{"id":44205455,"name":"corefxlab","full_name":"sokket/corefxlab","owner":{"login":"sokket","id":1761798,"avatar_url":"https://avatars.githubusercontent.com/u/1761798?v=3","gravatar_id":"","url":"https://api.github.com/users/sokket","html_url":"https://github.com/sokket","followers_url":"https://api.github.com/users/sokket/followers","following_url":"https://api.github.com/users/sokket/following{/other_user}","gists_url":"https://api.github.com/users/sokket/gists{/gist_id}","starred_url":"https://api.github.com/users/sokket/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sokket/subscriptions","organizations_url":"https://api.github.com/users/sokket/orgs","repos_url":"https://api.github.com/users/sokket/repos","events_url":"https://api.github.com/users/sokket/events{/privacy}","received_events_url":"https://api.github.com/users/sokket/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/sokket/corefxlab","description":"This repo is for experimentation and exploring new ideas that may or may not make it into the main corefx repo.","fork":true,"url":"https://api.github.com/repos/sokket/corefxlab","forks_url":"https://api.github.com/repos/sokket/corefxlab/forks","keys_url":"https://api.github.com/repos/sokket/corefxlab/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sokket/corefxlab/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sokket/corefxlab/teams","hooks_url":"https://api.github.com/repos/sokket/corefxlab/hooks","issue_events_url":"https://api.github.com/repos/sokket/corefxlab/issues/events{/number}","events_url":"https://api.github.com/repos/sokket/corefxlab/events","assignees_url":"https://api.github.com/repos/sokket/corefxlab/assignees{/user}","branches_url":"https://api.github.com/repos/sokket/corefxlab/branches{/branch}","tags_url":"https://api.github.com/repos/sokket/corefxlab/tags","blobs_url":"https://api.github.com/repos/sokket/corefxlab/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sokket/corefxlab/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sokket/corefxlab/git/refs{/sha}","trees_url":"https://api.github.com/repos/sokket/corefxlab/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sokket/corefxlab/statuses/{sha}","languages_url":"https://api.github.com/repos/sokket/corefxlab/languages","stargazers_url":"https://api.github.com/repos/sokket/corefxlab/stargazers","contributors_url":"https://api.github.com/repos/sokket/corefxlab/contributors","subscribers_url":"https://api.github.com/repos/sokket/corefxlab/subscribers","subscription_url":"https://api.github.com/repos/sokket/corefxlab/subscription","commits_url":"https://api.github.com/repos/sokket/corefxlab/commits{/sha}","git_commits_url":"https://api.github.com/repos/sokket/corefxlab/git/commits{/sha}","comments_url":"https://api.github.com/repos/sokket/corefxlab/comments{/number}","issue_comment_url":"https://api.github.com/repos/sokket/corefxlab/issues/comments{/number}","contents_url":"https://api.github.com/repos/sokket/corefxlab/contents/{+path}","compare_url":"https://api.github.com/repos/sokket/corefxlab/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sokket/corefxlab/merges","archive_url":"https://api.github.com/repos/sokket/corefxlab/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sokket/corefxlab/downloads","issues_url":"https://api.github.com/repos/sokket/corefxlab/issues{/number}","pulls_url":"https://api.github.com/repos/sokket/corefxlab/pulls{/number}","milestones_url":"https://api.github.com/repos/sokket/corefxlab/milestones{/number}","notifications_url":"https://api.github.com/repos/sokket/corefxlab/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sokket/corefxlab/labels{/name}","releases_url":"https://api.github.com/repos/sokket/corefxlab/releases{/id}","created_at":"2015-10-13T21:18:18Z","updated_at":"2015-10-13T21:18:21Z","pushed_at":"2015-10-22T21:36:11Z","git_url":"git://github.com/sokket/corefxlab.git","ssh_url":"git@github.com:sokket/corefxlab.git","clone_url":"https://github.com/sokket/corefxlab.git","svn_url":"https://github.com/sokket/corefxlab","homepage":"","size":19977,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"dotnet:master","ref":"master","sha":"3398d0dae44cd9b4121aecb88954d5a77131744e","user":{"login":"dotnet","id":9141961,"avatar_url":"https://avatars.githubusercontent.com/u/9141961?v=3","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"repo":{"id":29504192,"name":"corefxlab","full_name":"dotnet/corefxlab","owner":{"login":"dotnet","id":9141961,"avatar_url":"https://avatars.githubusercontent.com/u/9141961?v=3","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dotnet/corefxlab","description":"This repo is for experimentation and exploring new ideas that may or may not make it into the main corefx repo.","fork":false,"url":"https://api.github.com/repos/dotnet/corefxlab","forks_url":"https://api.github.com/repos/dotnet/corefxlab/forks","keys_url":"https://api.github.com/repos/dotnet/corefxlab/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dotnet/corefxlab/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dotnet/corefxlab/teams","hooks_url":"https://api.github.com/repos/dotnet/corefxlab/hooks","issue_events_url":"https://api.github.com/repos/dotnet/corefxlab/issues/events{/number}","events_url":"https://api.github.com/repos/dotnet/corefxlab/events","assignees_url":"https://api.github.com/repos/dotnet/corefxlab/assignees{/user}","branches_url":"https://api.github.com/repos/dotnet/corefxlab/branches{/branch}","tags_url":"https://api.github.com/repos/dotnet/corefxlab/tags","blobs_url":"https://api.github.com/repos/dotnet/corefxlab/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dotnet/corefxlab/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dotnet/corefxlab/git/refs{/sha}","trees_url":"https://api.github.com/repos/dotnet/corefxlab/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dotnet/corefxlab/statuses/{sha}","languages_url":"https://api.github.com/repos/dotnet/corefxlab/languages","stargazers_url":"https://api.github.com/repos/dotnet/corefxlab/stargazers","contributors_url":"https://api.github.com/repos/dotnet/corefxlab/contributors","subscribers_url":"https://api.github.com/repos/dotnet/corefxlab/subscribers","subscription_url":"https://api.github.com/repos/dotnet/corefxlab/subscription","commits_url":"https://api.github.com/repos/dotnet/corefxlab/commits{/sha}","git_commits_url":"https://api.github.com/repos/dotnet/corefxlab/git/commits{/sha}","comments_url":"https://api.github.com/repos/dotnet/corefxlab/comments{/number}","issue_comment_url":"https://api.github.com/repos/dotnet/corefxlab/issues/comments{/number}","contents_url":"https://api.github.com/repos/dotnet/corefxlab/contents/{+path}","compare_url":"https://api.github.com/repos/dotnet/corefxlab/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dotnet/corefxlab/merges","archive_url":"https://api.github.com/repos/dotnet/corefxlab/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dotnet/corefxlab/downloads","issues_url":"https://api.github.com/repos/dotnet/corefxlab/issues{/number}","pulls_url":"https://api.github.com/repos/dotnet/corefxlab/pulls{/number}","milestones_url":"https://api.github.com/repos/dotnet/corefxlab/milestones{/number}","notifications_url":"https://api.github.com/repos/dotnet/corefxlab/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dotnet/corefxlab/labels{/name}","releases_url":"https://api.github.com/repos/dotnet/corefxlab/releases{/id}","created_at":"2015-01-20T00:44:35Z","updated_at":"2015-10-21T15:54:24Z","pushed_at":"2015-10-22T21:36:36Z","git_url":"git://github.com/dotnet/corefxlab.git","ssh_url":"git@github.com:dotnet/corefxlab.git","clone_url":"https://github.com/dotnet/corefxlab.git","svn_url":"https://github.com/dotnet/corefxlab","homepage":"","size":21808,"stargazers_count":177,"watchers_count":177,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":78,"mirror_url":null,"open_issues_count":63,"forks":78,"open_issues":63,"watchers":177,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dotnet/corefxlab/pulls/353"},"html":{"href":"https://github.com/dotnet/corefxlab/pull/353"},"issue":{"href":"https://api.github.com/repos/dotnet/corefxlab/issues/353"},"comments":{"href":"https://api.github.com/repos/dotnet/corefxlab/issues/353/comments"},"review_comments":{"href":"https://api.github.com/repos/dotnet/corefxlab/pulls/353/comments"},"review_comment":{"href":"https://api.github.com/repos/dotnet/corefxlab/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dotnet/corefxlab/pulls/353/commits"},"statuses":{"href":"https://api.github.com/repos/dotnet/corefxlab/statuses/f9dc2b94fe65367c81685404770e3a386790d58c"}}}}