{"action":"created","comment":{"url":"https://api.github.com/repos/davidfowl/Channels/pulls/comments/80378135","id":80378135,"diff_hunk":"@@ -0,0 +1,90 @@\n+﻿using System;\n+using System.Collections.Generic;\n+using System.Linq;\n+using System.Runtime.CompilerServices;\n+using System.Threading.Tasks;\n+\n+namespace Channels\n+{\n+    public struct Memory<T>\n+    {\n+        private readonly T[] _array;\n+        private readonly int _offset;\n+        private readonly unsafe void* _memory;\n+        private readonly int _memoryLength;\n+\n+        public unsafe Memory(void* pointer, int offset, int length)\n+        {\n+            unsafe\n+            {\n+                _memory = pointer;\n+            }\n+\n+            _array = null;\n+            _offset = offset;\n+            _memoryLength = length;\n+        }\n+\n+        public unsafe Memory(T[] array, int offset, int length, void* pointer = null)\n+        {\n+            unsafe\n+            {\n+                _memory = pointer;\n+            }\n+\n+            _array = array;\n+            _offset = offset;\n+            _memoryLength = length;\n+        }\n+\n+        public Span<T> Span => this;\n+\n+        public bool IsEmpty => Length == 0;\n+\n+        public static implicit operator Span<T>(Memory<T> memory)\n+        {\n+            if (memory.Length == 0)\n+            {\n+                return Span<T>.Empty;\n+            }\n+\n+            if (memory._array != null)\n+            {\n+                return memory._array.Slice(memory._offset, memory.Length);\n+            }\n+            else\n+            {\n+                unsafe\n+                {\n+                    return new Span<T>(memory._memory, memory._memoryLength);\n+                }\n+            }\n+        }\n+\n+        public unsafe void* UnsafePointer => (byte*)_memory + (Unsafe.SizeOf<T>() * _offset);","path":"src/Channels/Memory.cs","position":64,"original_position":64,"commit_id":"75eb76e836204434c75e415ad546d0a382869c45","original_commit_id":"75eb76e836204434c75e415ad546d0a382869c45","user":{"login":"mgravell","id":17328,"avatar_url":"https://avatars.githubusercontent.com/u/17328?v=3","gravatar_id":"","url":"https://api.github.com/users/mgravell","html_url":"https://github.com/mgravell","followers_url":"https://api.github.com/users/mgravell/followers","following_url":"https://api.github.com/users/mgravell/following{/other_user}","gists_url":"https://api.github.com/users/mgravell/gists{/gist_id}","starred_url":"https://api.github.com/users/mgravell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mgravell/subscriptions","organizations_url":"https://api.github.com/users/mgravell/orgs","repos_url":"https://api.github.com/users/mgravell/repos","events_url":"https://api.github.com/users/mgravell/events{/privacy}","received_events_url":"https://api.github.com/users/mgravell/received_events","type":"User","site_admin":false},"body":"@davidfowl if the question there is \"should it, in the \"`_memory` is nil\" case, itself fetch the address from the array\", then IMO yeah, it feels like they should be accessing the array and using `fixed`, because *you can't know* that they have it pinned. However, the more immediate concern is that currently, in the \"`_memory` is nil\" case, this will return gibberish but non-zero gibberish. If we're lucky it'll still cause a memory access violation; if we're unlucky, they have a pointer to a random place in the process's memory.","created_at":"2016-09-25T09:47:42Z","updated_at":"2016-09-25T09:47:42Z","html_url":"https://github.com/davidfowl/Channels/pull/100#discussion_r80378135","pull_request_url":"https://api.github.com/repos/davidfowl/Channels/pulls/100","_links":{"self":{"href":"https://api.github.com/repos/davidfowl/Channels/pulls/comments/80378135"},"html":{"href":"https://github.com/davidfowl/Channels/pull/100#discussion_r80378135"},"pull_request":{"href":"https://api.github.com/repos/davidfowl/Channels/pulls/100"}}},"pull_request":{"url":"https://api.github.com/repos/davidfowl/Channels/pulls/100","id":86644286,"html_url":"https://github.com/davidfowl/Channels/pull/100","diff_url":"https://github.com/davidfowl/Channels/pull/100.diff","patch_url":"https://github.com/davidfowl/Channels/pull/100.patch","issue_url":"https://api.github.com/repos/davidfowl/Channels/issues/100","number":100,"state":"open","locked":false,"title":"Introduce Memory<T> type which represents a Span<T> promise","user":{"login":"davidfowl","id":95136,"avatar_url":"https://avatars.githubusercontent.com/u/95136?v=3","gravatar_id":"","url":"https://api.github.com/users/davidfowl","html_url":"https://github.com/davidfowl","followers_url":"https://api.github.com/users/davidfowl/followers","following_url":"https://api.github.com/users/davidfowl/following{/other_user}","gists_url":"https://api.github.com/users/davidfowl/gists{/gist_id}","starred_url":"https://api.github.com/users/davidfowl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidfowl/subscriptions","organizations_url":"https://api.github.com/users/davidfowl/orgs","repos_url":"https://api.github.com/users/davidfowl/repos","events_url":"https://api.github.com/users/davidfowl/events{/privacy}","received_events_url":"https://api.github.com/users/davidfowl/received_events","type":"User","site_admin":false},"body":"- This type is important because `Span<T>` is stack only so this serves as a\r\nsurrogate for doing normal things like async operations. It provides access to\r\nthe backing memory of `Span<T>` and should be considered unsafe. There's an\r\nimplicit conversion from `Memory<T>` -> `Span<T>` so it makes passing it to `Span<T>`\r\nAPIs easier.","created_at":"2016-09-25T08:55:50Z","updated_at":"2016-09-25T09:47:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e116e21cc4fbb1bfaa944211715f36abe0a059fc","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/davidfowl/Channels/pulls/100/commits","review_comments_url":"https://api.github.com/repos/davidfowl/Channels/pulls/100/comments","review_comment_url":"https://api.github.com/repos/davidfowl/Channels/pulls/comments{/number}","comments_url":"https://api.github.com/repos/davidfowl/Channels/issues/100/comments","statuses_url":"https://api.github.com/repos/davidfowl/Channels/statuses/75eb76e836204434c75e415ad546d0a382869c45","head":{"label":"davidfowl:davidfowl/memory-span-promise-async","ref":"davidfowl/memory-span-promise-async","sha":"75eb76e836204434c75e415ad546d0a382869c45","user":{"login":"davidfowl","id":95136,"avatar_url":"https://avatars.githubusercontent.com/u/95136?v=3","gravatar_id":"","url":"https://api.github.com/users/davidfowl","html_url":"https://github.com/davidfowl","followers_url":"https://api.github.com/users/davidfowl/followers","following_url":"https://api.github.com/users/davidfowl/following{/other_user}","gists_url":"https://api.github.com/users/davidfowl/gists{/gist_id}","starred_url":"https://api.github.com/users/davidfowl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidfowl/subscriptions","organizations_url":"https://api.github.com/users/davidfowl/orgs","repos_url":"https://api.github.com/users/davidfowl/repos","events_url":"https://api.github.com/users/davidfowl/events{/privacy}","received_events_url":"https://api.github.com/users/davidfowl/received_events","type":"User","site_admin":false},"repo":{"id":64905710,"name":"Channels","full_name":"davidfowl/Channels","owner":{"login":"davidfowl","id":95136,"avatar_url":"https://avatars.githubusercontent.com/u/95136?v=3","gravatar_id":"","url":"https://api.github.com/users/davidfowl","html_url":"https://github.com/davidfowl","followers_url":"https://api.github.com/users/davidfowl/followers","following_url":"https://api.github.com/users/davidfowl/following{/other_user}","gists_url":"https://api.github.com/users/davidfowl/gists{/gist_id}","starred_url":"https://api.github.com/users/davidfowl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidfowl/subscriptions","organizations_url":"https://api.github.com/users/davidfowl/orgs","repos_url":"https://api.github.com/users/davidfowl/repos","events_url":"https://api.github.com/users/davidfowl/events{/privacy}","received_events_url":"https://api.github.com/users/davidfowl/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/davidfowl/Channels","description":"Push based .NET Streams","fork":false,"url":"https://api.github.com/repos/davidfowl/Channels","forks_url":"https://api.github.com/repos/davidfowl/Channels/forks","keys_url":"https://api.github.com/repos/davidfowl/Channels/keys{/key_id}","collaborators_url":"https://api.github.com/repos/davidfowl/Channels/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/davidfowl/Channels/teams","hooks_url":"https://api.github.com/repos/davidfowl/Channels/hooks","issue_events_url":"https://api.github.com/repos/davidfowl/Channels/issues/events{/number}","events_url":"https://api.github.com/repos/davidfowl/Channels/events","assignees_url":"https://api.github.com/repos/davidfowl/Channels/assignees{/user}","branches_url":"https://api.github.com/repos/davidfowl/Channels/branches{/branch}","tags_url":"https://api.github.com/repos/davidfowl/Channels/tags","blobs_url":"https://api.github.com/repos/davidfowl/Channels/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/davidfowl/Channels/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/davidfowl/Channels/git/refs{/sha}","trees_url":"https://api.github.com/repos/davidfowl/Channels/git/trees{/sha}","statuses_url":"https://api.github.com/repos/davidfowl/Channels/statuses/{sha}","languages_url":"https://api.github.com/repos/davidfowl/Channels/languages","stargazers_url":"https://api.github.com/repos/davidfowl/Channels/stargazers","contributors_url":"https://api.github.com/repos/davidfowl/Channels/contributors","subscribers_url":"https://api.github.com/repos/davidfowl/Channels/subscribers","subscription_url":"https://api.github.com/repos/davidfowl/Channels/subscription","commits_url":"https://api.github.com/repos/davidfowl/Channels/commits{/sha}","git_commits_url":"https://api.github.com/repos/davidfowl/Channels/git/commits{/sha}","comments_url":"https://api.github.com/repos/davidfowl/Channels/comments{/number}","issue_comment_url":"https://api.github.com/repos/davidfowl/Channels/issues/comments{/number}","contents_url":"https://api.github.com/repos/davidfowl/Channels/contents/{+path}","compare_url":"https://api.github.com/repos/davidfowl/Channels/compare/{base}...{head}","merges_url":"https://api.github.com/repos/davidfowl/Channels/merges","archive_url":"https://api.github.com/repos/davidfowl/Channels/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/davidfowl/Channels/downloads","issues_url":"https://api.github.com/repos/davidfowl/Channels/issues{/number}","pulls_url":"https://api.github.com/repos/davidfowl/Channels/pulls{/number}","milestones_url":"https://api.github.com/repos/davidfowl/Channels/milestones{/number}","notifications_url":"https://api.github.com/repos/davidfowl/Channels/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/davidfowl/Channels/labels{/name}","releases_url":"https://api.github.com/repos/davidfowl/Channels/releases{/id}","deployments_url":"https://api.github.com/repos/davidfowl/Channels/deployments","created_at":"2016-08-04T05:38:45Z","updated_at":"2016-09-24T06:35:24Z","pushed_at":"2016-09-25T09:41:56Z","git_url":"git://github.com/davidfowl/Channels.git","ssh_url":"git@github.com:davidfowl/Channels.git","clone_url":"https://github.com/davidfowl/Channels.git","svn_url":"https://github.com/davidfowl/Channels","homepage":"","size":754,"stargazers_count":219,"watchers_count":219,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":28,"mirror_url":null,"open_issues_count":28,"forks":28,"open_issues":28,"watchers":219,"default_branch":"master"}},"base":{"label":"davidfowl:master","ref":"master","sha":"14aed65f1bfd2ce194cb1b8ecfdd24c77a3adb49","user":{"login":"davidfowl","id":95136,"avatar_url":"https://avatars.githubusercontent.com/u/95136?v=3","gravatar_id":"","url":"https://api.github.com/users/davidfowl","html_url":"https://github.com/davidfowl","followers_url":"https://api.github.com/users/davidfowl/followers","following_url":"https://api.github.com/users/davidfowl/following{/other_user}","gists_url":"https://api.github.com/users/davidfowl/gists{/gist_id}","starred_url":"https://api.github.com/users/davidfowl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidfowl/subscriptions","organizations_url":"https://api.github.com/users/davidfowl/orgs","repos_url":"https://api.github.com/users/davidfowl/repos","events_url":"https://api.github.com/users/davidfowl/events{/privacy}","received_events_url":"https://api.github.com/users/davidfowl/received_events","type":"User","site_admin":false},"repo":{"id":64905710,"name":"Channels","full_name":"davidfowl/Channels","owner":{"login":"davidfowl","id":95136,"avatar_url":"https://avatars.githubusercontent.com/u/95136?v=3","gravatar_id":"","url":"https://api.github.com/users/davidfowl","html_url":"https://github.com/davidfowl","followers_url":"https://api.github.com/users/davidfowl/followers","following_url":"https://api.github.com/users/davidfowl/following{/other_user}","gists_url":"https://api.github.com/users/davidfowl/gists{/gist_id}","starred_url":"https://api.github.com/users/davidfowl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidfowl/subscriptions","organizations_url":"https://api.github.com/users/davidfowl/orgs","repos_url":"https://api.github.com/users/davidfowl/repos","events_url":"https://api.github.com/users/davidfowl/events{/privacy}","received_events_url":"https://api.github.com/users/davidfowl/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/davidfowl/Channels","description":"Push based .NET Streams","fork":false,"url":"https://api.github.com/repos/davidfowl/Channels","forks_url":"https://api.github.com/repos/davidfowl/Channels/forks","keys_url":"https://api.github.com/repos/davidfowl/Channels/keys{/key_id}","collaborators_url":"https://api.github.com/repos/davidfowl/Channels/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/davidfowl/Channels/teams","hooks_url":"https://api.github.com/repos/davidfowl/Channels/hooks","issue_events_url":"https://api.github.com/repos/davidfowl/Channels/issues/events{/number}","events_url":"https://api.github.com/repos/davidfowl/Channels/events","assignees_url":"https://api.github.com/repos/davidfowl/Channels/assignees{/user}","branches_url":"https://api.github.com/repos/davidfowl/Channels/branches{/branch}","tags_url":"https://api.github.com/repos/davidfowl/Channels/tags","blobs_url":"https://api.github.com/repos/davidfowl/Channels/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/davidfowl/Channels/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/davidfowl/Channels/git/refs{/sha}","trees_url":"https://api.github.com/repos/davidfowl/Channels/git/trees{/sha}","statuses_url":"https://api.github.com/repos/davidfowl/Channels/statuses/{sha}","languages_url":"https://api.github.com/repos/davidfowl/Channels/languages","stargazers_url":"https://api.github.com/repos/davidfowl/Channels/stargazers","contributors_url":"https://api.github.com/repos/davidfowl/Channels/contributors","subscribers_url":"https://api.github.com/repos/davidfowl/Channels/subscribers","subscription_url":"https://api.github.com/repos/davidfowl/Channels/subscription","commits_url":"https://api.github.com/repos/davidfowl/Channels/commits{/sha}","git_commits_url":"https://api.github.com/repos/davidfowl/Channels/git/commits{/sha}","comments_url":"https://api.github.com/repos/davidfowl/Channels/comments{/number}","issue_comment_url":"https://api.github.com/repos/davidfowl/Channels/issues/comments{/number}","contents_url":"https://api.github.com/repos/davidfowl/Channels/contents/{+path}","compare_url":"https://api.github.com/repos/davidfowl/Channels/compare/{base}...{head}","merges_url":"https://api.github.com/repos/davidfowl/Channels/merges","archive_url":"https://api.github.com/repos/davidfowl/Channels/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/davidfowl/Channels/downloads","issues_url":"https://api.github.com/repos/davidfowl/Channels/issues{/number}","pulls_url":"https://api.github.com/repos/davidfowl/Channels/pulls{/number}","milestones_url":"https://api.github.com/repos/davidfowl/Channels/milestones{/number}","notifications_url":"https://api.github.com/repos/davidfowl/Channels/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/davidfowl/Channels/labels{/name}","releases_url":"https://api.github.com/repos/davidfowl/Channels/releases{/id}","deployments_url":"https://api.github.com/repos/davidfowl/Channels/deployments","created_at":"2016-08-04T05:38:45Z","updated_at":"2016-09-24T06:35:24Z","pushed_at":"2016-09-25T09:41:56Z","git_url":"git://github.com/davidfowl/Channels.git","ssh_url":"git@github.com:davidfowl/Channels.git","clone_url":"https://github.com/davidfowl/Channels.git","svn_url":"https://github.com/davidfowl/Channels","homepage":"","size":754,"stargazers_count":219,"watchers_count":219,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":28,"mirror_url":null,"open_issues_count":28,"forks":28,"open_issues":28,"watchers":219,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/davidfowl/Channels/pulls/100"},"html":{"href":"https://github.com/davidfowl/Channels/pull/100"},"issue":{"href":"https://api.github.com/repos/davidfowl/Channels/issues/100"},"comments":{"href":"https://api.github.com/repos/davidfowl/Channels/issues/100/comments"},"review_comments":{"href":"https://api.github.com/repos/davidfowl/Channels/pulls/100/comments"},"review_comment":{"href":"https://api.github.com/repos/davidfowl/Channels/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/davidfowl/Channels/pulls/100/commits"},"statuses":{"href":"https://api.github.com/repos/davidfowl/Channels/statuses/75eb76e836204434c75e415ad546d0a382869c45"}}}}
{"actor":{"display_login":"mgravell"}}