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 namespace trace_event { | |
14 class MemoryAllocatorDump; | |
15 class ProcessMemoryDump; | |
16 } | |
13 | 17 |
14 // Discardable memory is used to cache large objects without worrying about | 18 // 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 | 19 // 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 | 20 // 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 | 21 // experience. This is preferable to releasing memory in response to an OOM |
18 // signal because it is simpler and provides system-wide management of | 22 // signal because it is simpler and provides system-wide management of |
19 // purgable memory, though it has less flexibility as to which objects get | 23 // purgable memory, though it has less flexibility as to which objects get |
20 // discarded. | 24 // discarded. |
21 // | 25 // |
22 // Discardable memory has two states: locked and unlocked. While the memory is | 26 // Discardable memory has two states: locked and unlocked. While the memory is |
(...skipping 29 matching lines...) Expand all Loading... | |
52 virtual void Unlock() = 0; | 56 virtual void Unlock() = 0; |
53 | 57 |
54 // Returns the memory address held by this object. The object must be locked | 58 // Returns the memory address held by this object. The object must be locked |
55 // before calling this. | 59 // before calling this. |
56 virtual void* data() const = 0; | 60 virtual void* data() const = 0; |
57 | 61 |
58 // Handy method to simplify calling data() with a reinterpret_cast. | 62 // Handy method to simplify calling data() with a reinterpret_cast. |
59 template<typename T> T* data_as() const { | 63 template<typename T> T* data_as() const { |
60 return reinterpret_cast<T*>(data()); | 64 return reinterpret_cast<T*>(data()); |
61 } | 65 } |
66 | |
67 // Used for dumping the statistics of discardable memory allocated in tracing. | |
68 // Returns nullptr if the memory is purged by the allocator. Returns a new | |
reveman
2015/08/21 18:05:24
"Returns nullptr if the memory is purged by the al
ssid
2015/08/21 19:02:30
Yes that makes sense, I will make it dump size 0.
ssid
2015/08/24 14:52:09
Done.
| |
69 // MemoryAllocatorDump in the |pmd| with the size of the discardable memory. | |
70 // See ProcessMemoryDump::CreateAllocatorDump. | |
71 virtual trace_event::MemoryAllocatorDump* CreateMemoryAllocatorDump( | |
72 const char* name, | |
73 trace_event::ProcessMemoryDump* pmd) = 0; | |
62 }; | 74 }; |
63 | 75 |
64 } // namespace base | 76 } // namespace base |
65 | 77 |
66 #endif // BASE_MEMORY_DISCARDABLE_MEMORY_H_ | 78 #endif // BASE_MEMORY_DISCARDABLE_MEMORY_H_ |
OLD | NEW |