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

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: Synced 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
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..201bbeadf4c7ed6eacdd3dd443c80a4d03169081
--- /dev/null
+++ b/ios/chrome/browser/memory/memory_wedge.cc
@@ -0,0 +1,42 @@
+// 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 {
Alexei Svitkine (slow) 2015/04/28 16:52:58 Nit: Add an empty line after and before the closin
lpromero 2015/04/28 18:12:46 Done.
+// 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(unsigned wedge_size_in_mb) {
+ DCHECK(!gMemoryWedge);
+ if (wedge_size_in_mb == 0) {
Alexei Svitkine (slow) 2015/04/28 16:52:58 Nit: No {}'s
lpromero 2015/04/28 18:12:46 Done.
+ 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 RemoveWedge() {
+ DCHECK(gMemoryWedge);
+ free(gMemoryWedge);
+ gMemoryWedge = nullptr;
+}
+
+} // namespace memory_wedge

Powered by Google App Engine
This is Rietveld 408576698