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

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: Synced 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 {
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.
12 // Reference to the memory wedge. It is useful to:
13 // - make sure the compiler optimizations in Release don't skip |memset| and
14 // really end up putting the wedge in resident memory;
15 // - free it in tests.
16 static void* gMemoryWedge;
17
18 // The number of bytes in a megabyte.
19 const size_t kNumBytesInMB = 1024 * 1024;
20 } // namespace
21
22 namespace memory_wedge {
23
24 void AddWedge(unsigned wedge_size_in_mb) {
25 DCHECK(!gMemoryWedge);
26 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.
27 return;
28 }
29
30 // Allocate a wedge and write to it to have it in resident memory.
31 const size_t wedge_size = wedge_size_in_mb * kNumBytesInMB;
32 gMemoryWedge = malloc(wedge_size);
33 memset(gMemoryWedge, -1, wedge_size);
34 }
35
36 void RemoveWedge() {
37 DCHECK(gMemoryWedge);
38 free(gMemoryWedge);
39 gMemoryWedge = nullptr;
40 }
41
42 } // namespace memory_wedge
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698