{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/corefx/issues/5474","repository_url":"https://api.github.com/repos/dotnet/corefx","labels_url":"https://api.github.com/repos/dotnet/corefx/issues/5474/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/corefx/issues/5474/comments","events_url":"https://api.github.com/repos/dotnet/corefx/issues/5474/events","html_url":"https://github.com/dotnet/corefx/issues/5474","id":126977441,"number":5474,"title":"Provide a generic API to read from and write to a pointer","user":{"login":"terrajobst","id":5169960,"avatar_url":"https://avatars.githubusercontent.com/u/5169960?v=3","gravatar_id":"","url":"https://api.github.com/users/terrajobst","html_url":"https://github.com/terrajobst","followers_url":"https://api.github.com/users/terrajobst/followers","following_url":"https://api.github.com/users/terrajobst/following{/other_user}","gists_url":"https://api.github.com/users/terrajobst/gists{/gist_id}","starred_url":"https://api.github.com/users/terrajobst/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/terrajobst/subscriptions","organizations_url":"https://api.github.com/users/terrajobst/orgs","repos_url":"https://api.github.com/users/terrajobst/repos","events_url":"https://api.github.com/users/terrajobst/events{/privacy}","received_events_url":"https://api.github.com/users/terrajobst/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/dotnet/corefx/labels/api-needs-work","name":"api-needs-work","color":"207de5"},{"url":"https://api.github.com/repos/dotnet/corefx/labels/System.Runtime","name":"System.Runtime","color":"d4c5f9"}],"state":"open","locked":false,"assignee":{"login":"mellinoe","id":8918977,"avatar_url":"https://avatars.githubusercontent.com/u/8918977?v=3","gravatar_id":"","url":"https://api.github.com/users/mellinoe","html_url":"https://github.com/mellinoe","followers_url":"https://api.github.com/users/mellinoe/followers","following_url":"https://api.github.com/users/mellinoe/following{/other_user}","gists_url":"https://api.github.com/users/mellinoe/gists{/gist_id}","starred_url":"https://api.github.com/users/mellinoe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mellinoe/subscriptions","organizations_url":"https://api.github.com/users/mellinoe/orgs","repos_url":"https://api.github.com/users/mellinoe/repos","events_url":"https://api.github.com/users/mellinoe/events{/privacy}","received_events_url":"https://api.github.com/users/mellinoe/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/dotnet/corefx/milestones/4","html_url":"https://github.com/dotnet/corefx/milestones/1.0.0-rtm","labels_url":"https://api.github.com/repos/dotnet/corefx/milestones/4/labels","id":1248719,"number":4,"title":"1.0.0-rtm","description":"Q1 2016 (https://github.com/aspnet/Home/wiki/Roadmap)","creator":{"login":"joshfree","id":1302850,"avatar_url":"https://avatars.githubusercontent.com/u/1302850?v=3","gravatar_id":"","url":"https://api.github.com/users/joshfree","html_url":"https://github.com/joshfree","followers_url":"https://api.github.com/users/joshfree/followers","following_url":"https://api.github.com/users/joshfree/following{/other_user}","gists_url":"https://api.github.com/users/joshfree/gists{/gist_id}","starred_url":"https://api.github.com/users/joshfree/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joshfree/subscriptions","organizations_url":"https://api.github.com/users/joshfree/orgs","repos_url":"https://api.github.com/users/joshfree/repos","events_url":"https://api.github.com/users/joshfree/events{/privacy}","received_events_url":"https://api.github.com/users/joshfree/received_events","type":"User","site_admin":false},"open_issues":230,"closed_issues":232,"state":"open","created_at":"2015-08-10T18:04:00Z","updated_at":"2016-02-09T15:37:46Z","due_on":"2016-03-31T07:00:00Z","closed_at":null},"comments":42,"created_at":"2016-01-15T23:09:31Z","updated_at":"2016-02-09T16:35:13Z","closed_at":null,"body":"C# doesn't support pointer operations on generic types. We can, however, express them in IL. A prototype could like this:\r\n\r\n```C#\r\npublic static class Unsafe\r\n{\r\n      [MethodImpl(MethodImplOptions.AggressiveInlining)]\r\n      public static T Read<T>(void * p)\r\n      {\r\n          // Can't be expressed in C#, thus in IL:\r\n          ldarg.0\r\n          ldobj !!T\r\n          ret\r\n      }\r\n\r\n      [MethodImpl(MethodImplOptions.AggressiveInlining)]\r\n      public static void Write<T>(void * p, T value)\r\n      {\r\n          // Can't be expressed in C#, thus in IL:\r\n          ldarg.0\r\n          ldarg.1\r\n          stobj !!T\r\n          ret\r\n      }\r\n}\r\n```\r\n\r\nThis would also solve issues like #5202 without any additional work."},"comment":{"url":"https://api.github.com/repos/dotnet/corefx/issues/comments/181945884","html_url":"https://github.com/dotnet/corefx/issues/5474#issuecomment-181945884","issue_url":"https://api.github.com/repos/dotnet/corefx/issues/5474","id":181945884,"user":{"login":"CarolEidt","id":2973870,"avatar_url":"https://avatars.githubusercontent.com/u/2973870?v=3","gravatar_id":"","url":"https://api.github.com/users/CarolEidt","html_url":"https://github.com/CarolEidt","followers_url":"https://api.github.com/users/CarolEidt/followers","following_url":"https://api.github.com/users/CarolEidt/following{/other_user}","gists_url":"https://api.github.com/users/CarolEidt/gists{/gist_id}","starred_url":"https://api.github.com/users/CarolEidt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CarolEidt/subscriptions","organizations_url":"https://api.github.com/users/CarolEidt/orgs","repos_url":"https://api.github.com/users/CarolEidt/repos","events_url":"https://api.github.com/users/CarolEidt/events{/privacy}","received_events_url":"https://api.github.com/users/CarolEidt/received_events","type":"User","site_admin":false},"created_at":"2016-02-09T16:35:13Z","updated_at":"2016-02-09T16:35:13Z","body":"@AndyAyersMS may want to comment, as he is working on refactoring (and ultimately tuning) the inlining code in the JIT. The JIT could potentially try to do something to adjust for a mismatch, but I think it could be potentially error-prone or unsafe, and of limited value."}}