{"action":"created","comment":{"url":"https://api.github.com/repos/dotnet/roslyn/pulls/comments/63446868","id":63446868,"diff_hunk":"@@ -0,0 +1,141 @@\n+﻿// Copyright (c) Microsoft.  All Rights Reserved.  Licensed under the Apache License, Version 2.0.  See License.txt in the project root for license information.\n+\n+using System;\n+using System.Collections.Generic;\n+using System.Threading.Tasks;\n+\n+namespace Roslyn.VisualStudio.DiagnosticsWindow.OptionsPages\n+{\n+    internal class ForceLowMemoryMode\n+    {\n+        private int _size = 500;  // default to 500 MB\n+        private MemoryHogger _hogger;\n+\n+        public static readonly ForceLowMemoryMode Instance = new ForceLowMemoryMode();\n+\n+        private ForceLowMemoryMode()\n+        {\n+        }\n+\n+        public int Size\n+        {\n+            get { return _size; }\n+            set { _size = value; }\n+        }\n+\n+        public bool Enabled\n+        {\n+            get\n+            {\n+                return _hogger != null;\n+            }\n+\n+            set\n+            {\n+                if (value && _hogger == null)\n+                {\n+                    _hogger = new MemoryHogger();\n+                    var tmp = _hogger.PopulateAndMonitorAsync(this.Size);\n+                }\n+                else if (!value)\n+                {\n+                    var hogger = _hogger;\n+                    if (hogger != null)\n+                    {\n+                        _hogger = null;\n+                        hogger.Cancel();\n+                    }\n+                }\n+            }\n+        }\n+\n+        class MemoryHogger\n+        {\n+            private const int BlockSize = 1024 * 1024; // megabyte blocks\n+            private const int MonitorDelay = 10000; // 10 seconds\n+\n+            private readonly List<byte[]> _blocks = new List<byte[]>();\n+            private bool _cancelled;\n+\n+            public MemoryHogger()\n+            {\n+            }\n+\n+            public int Count\n+            {\n+                get { return _blocks.Count; }\n+            }\n+\n+            public void Cancel()\n+            {\n+                _cancelled = true;\n+            }\n+\n+            public Task PopulateAndMonitorAsync(int size)\n+            {\n+                // run on background thread\n+                return Task.Run(() => this.PopulateAndMonitorWorkerAsync(size));\n+            }\n+\n+            private async Task PopulateAndMonitorWorkerAsync(int size)\n+            {\n+                try\n+                {\n+                    for (int n = 0; n < size && !_cancelled; n++)\n+                    {\n+                        var block = new byte[BlockSize];\n+\n+                        // initialize block bits (so they memory actually gets allocated.. silly runtime!)\n+                        for (int i = 0; i < BlockSize; i++)\n+                        {\n+                            block[i] = 0xFF;\n+                        }\n+\n+                        _blocks.Add(block);\n+\n+                        // don't hog the thread\n+                        await Task.Yield();\n+                    }\n+                }\n+                catch (Exception)\n+                {\n+                }\n+\n+                // monitor memory to keep it paged in\n+                while (!_cancelled)\n+                {\n+                    try\n+                    {\n+                        // access all block cells\n+                        for (var b = 0; b < _blocks.Count && !_cancelled; b++)\n+                        {\n+                            var block = _blocks[b];\n+\n+                            for (int i = 0; i < block.Length; i++)\n+                            {\n+                                var tmp = block[i]; // read bytes from block","path":"src/VisualStudio/VisualStudioDiagnosticsToolWindow/OptionPages/ForceLowMemoryMode.cs","position":116,"original_position":116,"commit_id":"f230c5d5d349246a0dd40ce629a20a11072887b4","original_commit_id":"f230c5d5d349246a0dd40ce629a20a11072887b4","user":{"login":"jasonmalinowski","id":201340,"avatar_url":"https://avatars.githubusercontent.com/u/201340?v=3","gravatar_id":"","url":"https://api.github.com/users/jasonmalinowski","html_url":"https://github.com/jasonmalinowski","followers_url":"https://api.github.com/users/jasonmalinowski/followers","following_url":"https://api.github.com/users/jasonmalinowski/following{/other_user}","gists_url":"https://api.github.com/users/jasonmalinowski/gists{/gist_id}","starred_url":"https://api.github.com/users/jasonmalinowski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jasonmalinowski/subscriptions","organizations_url":"https://api.github.com/users/jasonmalinowski/orgs","repos_url":"https://api.github.com/users/jasonmalinowski/repos","events_url":"https://api.github.com/users/jasonmalinowski/events{/privacy}","received_events_url":"https://api.github.com/users/jasonmalinowski/received_events","type":"User","site_admin":false},"body":"Is the compiler or runtime entitled to optimize this away? @jaredpar?","created_at":"2016-05-17T00:02:58Z","updated_at":"2016-05-17T00:02:58Z","html_url":"https://github.com/dotnet/roslyn/pull/11355#discussion_r63446868","pull_request_url":"https://api.github.com/repos/dotnet/roslyn/pulls/11355","_links":{"self":{"href":"https://api.github.com/repos/dotnet/roslyn/pulls/comments/63446868"},"html":{"href":"https://github.com/dotnet/roslyn/pull/11355#discussion_r63446868"},"pull_request":{"href":"https://api.github.com/repos/dotnet/roslyn/pulls/11355"}}},"pull_request":{"url":"https://api.github.com/repos/dotnet/roslyn/pulls/11355","id":70279421,"html_url":"https://github.com/dotnet/roslyn/pull/11355","diff_url":"https://github.com/dotnet/roslyn/pull/11355.diff","patch_url":"https://github.com/dotnet/roslyn/pull/11355.patch","issue_url":"https://api.github.com/repos/dotnet/roslyn/issues/11355","number":11355,"state":"open","locked":false,"title":"Add Forced Low Memory Mode feature","user":{"login":"mattwar","id":3387305,"avatar_url":"https://avatars.githubusercontent.com/u/3387305?v=3","gravatar_id":"","url":"https://api.github.com/users/mattwar","html_url":"https://github.com/mattwar","followers_url":"https://api.github.com/users/mattwar/followers","following_url":"https://api.github.com/users/mattwar/following{/other_user}","gists_url":"https://api.github.com/users/mattwar/gists{/gist_id}","starred_url":"https://api.github.com/users/mattwar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattwar/subscriptions","organizations_url":"https://api.github.com/users/mattwar/orgs","repos_url":"https://api.github.com/users/mattwar/repos","events_url":"https://api.github.com/users/mattwar/events{/privacy}","received_events_url":"https://api.github.com/users/mattwar/received_events","type":"User","site_admin":false},"body":"Issue #11354 \r\n\r\nThis adds an option that lets Roslyn developers put their VS process into a low memory mode. This will simulate a VS install with more constrained address space.\r\n\r\n@mattgertz @jasonmalinowski @jared @Pilchie please review","created_at":"2016-05-16T23:41:59Z","updated_at":"2016-05-17T00:02:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f8fab159b2c150f354be8f857b9c9a452aebfc25","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/dotnet/roslyn/pulls/11355/commits","review_comments_url":"https://api.github.com/repos/dotnet/roslyn/pulls/11355/comments","review_comment_url":"https://api.github.com/repos/dotnet/roslyn/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dotnet/roslyn/issues/11355/comments","statuses_url":"https://api.github.com/repos/dotnet/roslyn/statuses/f230c5d5d349246a0dd40ce629a20a11072887b4","head":{"label":"mattwar:ForcedLowMemoryMode","ref":"ForcedLowMemoryMode","sha":"f230c5d5d349246a0dd40ce629a20a11072887b4","user":{"login":"mattwar","id":3387305,"avatar_url":"https://avatars.githubusercontent.com/u/3387305?v=3","gravatar_id":"","url":"https://api.github.com/users/mattwar","html_url":"https://github.com/mattwar","followers_url":"https://api.github.com/users/mattwar/followers","following_url":"https://api.github.com/users/mattwar/following{/other_user}","gists_url":"https://api.github.com/users/mattwar/gists{/gist_id}","starred_url":"https://api.github.com/users/mattwar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattwar/subscriptions","organizations_url":"https://api.github.com/users/mattwar/orgs","repos_url":"https://api.github.com/users/mattwar/repos","events_url":"https://api.github.com/users/mattwar/events{/privacy}","received_events_url":"https://api.github.com/users/mattwar/received_events","type":"User","site_admin":false},"repo":{"id":30200787,"name":"roslyn","full_name":"mattwar/roslyn","owner":{"login":"mattwar","id":3387305,"avatar_url":"https://avatars.githubusercontent.com/u/3387305?v=3","gravatar_id":"","url":"https://api.github.com/users/mattwar","html_url":"https://github.com/mattwar","followers_url":"https://api.github.com/users/mattwar/followers","following_url":"https://api.github.com/users/mattwar/following{/other_user}","gists_url":"https://api.github.com/users/mattwar/gists{/gist_id}","starred_url":"https://api.github.com/users/mattwar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattwar/subscriptions","organizations_url":"https://api.github.com/users/mattwar/orgs","repos_url":"https://api.github.com/users/mattwar/repos","events_url":"https://api.github.com/users/mattwar/events{/privacy}","received_events_url":"https://api.github.com/users/mattwar/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mattwar/roslyn","description":"The .NET Compiler Platform (\"Roslyn\") provides open-source C# and Visual Basic compilers with rich code analysis APIs.","fork":true,"url":"https://api.github.com/repos/mattwar/roslyn","forks_url":"https://api.github.com/repos/mattwar/roslyn/forks","keys_url":"https://api.github.com/repos/mattwar/roslyn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mattwar/roslyn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mattwar/roslyn/teams","hooks_url":"https://api.github.com/repos/mattwar/roslyn/hooks","issue_events_url":"https://api.github.com/repos/mattwar/roslyn/issues/events{/number}","events_url":"https://api.github.com/repos/mattwar/roslyn/events","assignees_url":"https://api.github.com/repos/mattwar/roslyn/assignees{/user}","branches_url":"https://api.github.com/repos/mattwar/roslyn/branches{/branch}","tags_url":"https://api.github.com/repos/mattwar/roslyn/tags","blobs_url":"https://api.github.com/repos/mattwar/roslyn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mattwar/roslyn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mattwar/roslyn/git/refs{/sha}","trees_url":"https://api.github.com/repos/mattwar/roslyn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mattwar/roslyn/statuses/{sha}","languages_url":"https://api.github.com/repos/mattwar/roslyn/languages","stargazers_url":"https://api.github.com/repos/mattwar/roslyn/stargazers","contributors_url":"https://api.github.com/repos/mattwar/roslyn/contributors","subscribers_url":"https://api.github.com/repos/mattwar/roslyn/subscribers","subscription_url":"https://api.github.com/repos/mattwar/roslyn/subscription","commits_url":"https://api.github.com/repos/mattwar/roslyn/commits{/sha}","git_commits_url":"https://api.github.com/repos/mattwar/roslyn/git/commits{/sha}","comments_url":"https://api.github.com/repos/mattwar/roslyn/comments{/number}","issue_comment_url":"https://api.github.com/repos/mattwar/roslyn/issues/comments{/number}","contents_url":"https://api.github.com/repos/mattwar/roslyn/contents/{+path}","compare_url":"https://api.github.com/repos/mattwar/roslyn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mattwar/roslyn/merges","archive_url":"https://api.github.com/repos/mattwar/roslyn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mattwar/roslyn/downloads","issues_url":"https://api.github.com/repos/mattwar/roslyn/issues{/number}","pulls_url":"https://api.github.com/repos/mattwar/roslyn/pulls{/number}","milestones_url":"https://api.github.com/repos/mattwar/roslyn/milestones{/number}","notifications_url":"https://api.github.com/repos/mattwar/roslyn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mattwar/roslyn/labels{/name}","releases_url":"https://api.github.com/repos/mattwar/roslyn/releases{/id}","deployments_url":"https://api.github.com/repos/mattwar/roslyn/deployments","created_at":"2015-02-02T18:12:54Z","updated_at":"2016-01-19T21:03:29Z","pushed_at":"2016-05-16T23:40:24Z","git_url":"git://github.com/mattwar/roslyn.git","ssh_url":"git@github.com:mattwar/roslyn.git","clone_url":"https://github.com/mattwar/roslyn.git","svn_url":"https://github.com/mattwar/roslyn","homepage":"","size":144307,"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":"d2a3f73f467d3a8116e0e4c9ca2b2dfb5952394b","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":29078997,"name":"roslyn","full_name":"dotnet/roslyn","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/roslyn","description":"The .NET Compiler Platform (\"Roslyn\") provides open-source C# and Visual Basic compilers with rich code analysis APIs.","fork":false,"url":"https://api.github.com/repos/dotnet/roslyn","forks_url":"https://api.github.com/repos/dotnet/roslyn/forks","keys_url":"https://api.github.com/repos/dotnet/roslyn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dotnet/roslyn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dotnet/roslyn/teams","hooks_url":"https://api.github.com/repos/dotnet/roslyn/hooks","issue_events_url":"https://api.github.com/repos/dotnet/roslyn/issues/events{/number}","events_url":"https://api.github.com/repos/dotnet/roslyn/events","assignees_url":"https://api.github.com/repos/dotnet/roslyn/assignees{/user}","branches_url":"https://api.github.com/repos/dotnet/roslyn/branches{/branch}","tags_url":"https://api.github.com/repos/dotnet/roslyn/tags","blobs_url":"https://api.github.com/repos/dotnet/roslyn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dotnet/roslyn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dotnet/roslyn/git/refs{/sha}","trees_url":"https://api.github.com/repos/dotnet/roslyn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dotnet/roslyn/statuses/{sha}","languages_url":"https://api.github.com/repos/dotnet/roslyn/languages","stargazers_url":"https://api.github.com/repos/dotnet/roslyn/stargazers","contributors_url":"https://api.github.com/repos/dotnet/roslyn/contributors","subscribers_url":"https://api.github.com/repos/dotnet/roslyn/subscribers","subscription_url":"https://api.github.com/repos/dotnet/roslyn/subscription","commits_url":"https://api.github.com/repos/dotnet/roslyn/commits{/sha}","git_commits_url":"https://api.github.com/repos/dotnet/roslyn/git/commits{/sha}","comments_url":"https://api.github.com/repos/dotnet/roslyn/comments{/number}","issue_comment_url":"https://api.github.com/repos/dotnet/roslyn/issues/comments{/number}","contents_url":"https://api.github.com/repos/dotnet/roslyn/contents/{+path}","compare_url":"https://api.github.com/repos/dotnet/roslyn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dotnet/roslyn/merges","archive_url":"https://api.github.com/repos/dotnet/roslyn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dotnet/roslyn/downloads","issues_url":"https://api.github.com/repos/dotnet/roslyn/issues{/number}","pulls_url":"https://api.github.com/repos/dotnet/roslyn/pulls{/number}","milestones_url":"https://api.github.com/repos/dotnet/roslyn/milestones{/number}","notifications_url":"https://api.github.com/repos/dotnet/roslyn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dotnet/roslyn/labels{/name}","releases_url":"https://api.github.com/repos/dotnet/roslyn/releases{/id}","deployments_url":"https://api.github.com/repos/dotnet/roslyn/deployments","created_at":"2015-01-11T02:39:03Z","updated_at":"2016-05-16T21:29:03Z","pushed_at":"2016-05-16T23:41:59Z","git_url":"git://github.com/dotnet/roslyn.git","ssh_url":"git@github.com:dotnet/roslyn.git","clone_url":"https://github.com/dotnet/roslyn.git","svn_url":"https://github.com/dotnet/roslyn","homepage":"","size":293647,"stargazers_count":5137,"watchers_count":5137,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1295,"mirror_url":null,"open_issues_count":2767,"forks":1295,"open_issues":2767,"watchers":5137,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dotnet/roslyn/pulls/11355"},"html":{"href":"https://github.com/dotnet/roslyn/pull/11355"},"issue":{"href":"https://api.github.com/repos/dotnet/roslyn/issues/11355"},"comments":{"href":"https://api.github.com/repos/dotnet/roslyn/issues/11355/comments"},"review_comments":{"href":"https://api.github.com/repos/dotnet/roslyn/pulls/11355/comments"},"review_comment":{"href":"https://api.github.com/repos/dotnet/roslyn/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dotnet/roslyn/pulls/11355/commits"},"statuses":{"href":"https://api.github.com/repos/dotnet/roslyn/statuses/f230c5d5d349246a0dd40ce629a20a11072887b4"}}}}