OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_MEMORY_DISCARDABLE_MEMORY_H_ | 5 #ifndef BASE_MEMORY_DISCARDABLE_MEMORY_H_ |
6 #define BASE_MEMORY_DISCARDABLE_MEMORY_H_ | 6 #define BASE_MEMORY_DISCARDABLE_MEMORY_H_ |
7 | 7 |
8 #include "base/base_export.h" | 8 #include "base/base_export.h" |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 | 11 |
12 namespace base { | 12 namespace base { |
13 | 13 |
| 14 namespace trace_event { |
| 15 class MemoryAllocatorDump; |
| 16 class ProcessMemoryDump; |
| 17 } |
| 18 |
14 // Discardable memory is used to cache large objects without worrying about | 19 // Discardable memory is used to cache large objects without worrying about |
15 // blowing out memory, both on mobile devices where there is no swap, and | 20 // blowing out memory, both on mobile devices where there is no swap, and |
16 // desktop devices where unused free memory should be used to help the user | 21 // desktop devices where unused free memory should be used to help the user |
17 // experience. This is preferable to releasing memory in response to an OOM | 22 // experience. This is preferable to releasing memory in response to an OOM |
18 // signal because it is simpler and provides system-wide management of | 23 // signal because it is simpler and provides system-wide management of |
19 // purgable memory, though it has less flexibility as to which objects get | 24 // purgable memory, though it has less flexibility as to which objects get |
20 // discarded. | 25 // discarded. |
21 // | 26 // |
22 // Discardable memory has two states: locked and unlocked. While the memory is | 27 // Discardable memory has two states: locked and unlocked. While the memory is |
23 // locked, it will not be discarded. Unlocking the memory allows the | 28 // locked, it will not be discarded. Unlocking the memory allows the |
(...skipping 28 matching lines...) Expand all Loading... |
52 virtual void Unlock() = 0; | 57 virtual void Unlock() = 0; |
53 | 58 |
54 // Returns the memory address held by this object. The object must be locked | 59 // Returns the memory address held by this object. The object must be locked |
55 // before calling this. | 60 // before calling this. |
56 virtual void* data() const = 0; | 61 virtual void* data() const = 0; |
57 | 62 |
58 // Handy method to simplify calling data() with a reinterpret_cast. | 63 // Handy method to simplify calling data() with a reinterpret_cast. |
59 template<typename T> T* data_as() const { | 64 template<typename T> T* data_as() const { |
60 return reinterpret_cast<T*>(data()); | 65 return reinterpret_cast<T*>(data()); |
61 } | 66 } |
| 67 |
| 68 // Used for dumping the statistics of discardable memory allocated in tracing. |
| 69 // Returns a new MemoryAllocatorDump in the |pmd| with the size of the |
| 70 // discardable memory. The MemoryAllocatorDump created is owned by |pmd|. See |
| 71 // ProcessMemoryDump::CreateAllocatorDump. |
| 72 virtual trace_event::MemoryAllocatorDump* CreateMemoryAllocatorDump( |
| 73 const char* name, |
| 74 trace_event::ProcessMemoryDump* pmd) const = 0; |
62 }; | 75 }; |
63 | 76 |
64 } // namespace base | 77 } // namespace base |
65 | 78 |
66 #endif // BASE_MEMORY_DISCARDABLE_MEMORY_H_ | 79 #endif // BASE_MEMORY_DISCARDABLE_MEMORY_H_ |
OLD | NEW |