Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Unified Diff: ios/chrome/browser/memory/memory_wedge.cc

Issue 1107963002: Add MemoryWedge to ios/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review feedback. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/chrome/browser/memory/memory_wedge.h ('k') | ios/chrome/browser/memory/memory_wedge_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/memory/memory_wedge.cc
diff --git a/ios/chrome/browser/memory/memory_wedge.cc b/ios/chrome/browser/memory/memory_wedge.cc
new file mode 100644
index 0000000000000000000000000000000000000000..10e885e7372b64dffd47275c0b90ec9861743310
--- /dev/null
+++ b/ios/chrome/browser/memory/memory_wedge.cc
@@ -0,0 +1,43 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ios/chrome/browser/memory/memory_wedge.h"
+
+#include <stdlib.h>
+
+#include "base/logging.h"
+
+namespace {
+
+// Reference to the memory wedge. It is useful to:
+// - make sure the compiler optimizations in Release don't skip |memset| and
+// really end up putting the wedge in resident memory;
+// - free it in tests.
+static void* gMemoryWedge;
+
+// The number of bytes in a megabyte.
+const size_t kNumBytesInMB = 1024 * 1024;
+
+} // namespace
+
+namespace memory_wedge {
+
+void AddWedge(size_t wedge_size_in_mb) {
+ DCHECK(!gMemoryWedge);
+ if (wedge_size_in_mb == 0)
+ return;
+
+ // Allocate a wedge and write to it to have it in resident memory.
+ const size_t wedge_size = wedge_size_in_mb * kNumBytesInMB;
+ gMemoryWedge = malloc(wedge_size);
+ memset(gMemoryWedge, -1, wedge_size);
+}
+
+void RemoveWedgeForTesting() {
+ DCHECK(gMemoryWedge);
+ free(gMemoryWedge);
+ gMemoryWedge = nullptr;
+}
+
+} // namespace memory_wedge
« no previous file with comments | « ios/chrome/browser/memory/memory_wedge.h ('k') | ios/chrome/browser/memory/memory_wedge_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698