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.
5 #include "ios/chrome/browser/memory/memory_wedge.h"
9 #include "base/logging.h"
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
;
19 // The number of bytes in a megabyte.
20 const size_t kNumBytesInMB
= 1024 * 1024;
24 namespace memory_wedge
{
26 void AddWedge(size_t wedge_size_in_mb
) {
27 DCHECK(!gMemoryWedge
);
28 if (wedge_size_in_mb
== 0)
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
);
37 void RemoveWedgeForTesting() {
40 gMemoryWedge
= nullptr;
43 } // namespace memory_wedge