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

Side by Side 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, 7 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ios/chrome/browser/memory/memory_wedge.h"
6
7 #include <stdlib.h>
8
9 #include "base/logging.h"
10
11 namespace {
12
13 // Reference to the memory wedge. It is useful to:
14 // - make sure the compiler optimizations in Release don't skip |memset| and
15 // really end up putting the wedge in resident memory;
16 // - free it in tests.
17 static void* gMemoryWedge;
18
19 // The number of bytes in a megabyte.
20 const size_t kNumBytesInMB = 1024 * 1024;
21
22 } // namespace
23
24 namespace memory_wedge {
25
26 void AddWedge(size_t wedge_size_in_mb) {
27 DCHECK(!gMemoryWedge);
28 if (wedge_size_in_mb == 0)
29 return;
30
31 // Allocate a wedge and write to it to have it in resident memory.
32 const size_t wedge_size = wedge_size_in_mb * kNumBytesInMB;
33 gMemoryWedge = malloc(wedge_size);
34 memset(gMemoryWedge, -1, wedge_size);
35 }
36
37 void RemoveWedgeForTesting() {
38 DCHECK(gMemoryWedge);
39 free(gMemoryWedge);
40 gMemoryWedge = nullptr;
41 }
42
43 } // namespace memory_wedge
OLDNEW
« 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