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 <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 // Gets the preferred discardable memory type. | 90 // Gets the preferred discardable memory type. |
91 static DiscardableMemoryType GetPreferredType(); | 91 static DiscardableMemoryType GetPreferredType(); |
92 | 92 |
93 // Create a DiscardableMemory instance with specified |type| and |size|. | 93 // Create a DiscardableMemory instance with specified |type| and |size|. |
94 static scoped_ptr<DiscardableMemory> CreateLockedMemoryWithType( | 94 static scoped_ptr<DiscardableMemory> CreateLockedMemoryWithType( |
95 DiscardableMemoryType type, size_t size); | 95 DiscardableMemoryType type, size_t size); |
96 | 96 |
97 // Create a DiscardableMemory instance with preferred type and |size|. | 97 // Create a DiscardableMemory instance with preferred type and |size|. |
98 static scoped_ptr<DiscardableMemory> CreateLockedMemory(size_t size); | 98 static scoped_ptr<DiscardableMemory> CreateLockedMemory(size_t size); |
99 | 99 |
| 100 // Discardable memory implementations might allow an elevated usage level |
| 101 // while in frequent use. Call this to have the usage reduced to the base |
| 102 // level. Returns true if there's no need to call this again until |
| 103 // memory instances have been used. This indicates that all discardable |
| 104 // memory implementations have reduced usage to the base level or below. |
| 105 // Note: calling this too often or while discardable memory is in frequent |
| 106 // use can hurt performance, whereas calling it too infrequently can result |
| 107 // in memory bloat. |
| 108 static bool ReduceMemoryUsage(); |
| 109 |
100 // Locks the memory so that it will not be purged by the system. Returns | 110 // Locks the memory so that it will not be purged by the system. Returns |
101 // DISCARDABLE_MEMORY_LOCK_STATUS_SUCCESS on success. If the return value is | 111 // DISCARDABLE_MEMORY_LOCK_STATUS_SUCCESS on success. If the return value is |
102 // DISCARDABLE_MEMORY_LOCK_STATUS_FAILED then this object should be | 112 // DISCARDABLE_MEMORY_LOCK_STATUS_FAILED then this object should be |
103 // discarded and a new one should be created. If the return value is | 113 // discarded and a new one should be created. If the return value is |
104 // DISCARDABLE_MEMORY_LOCK_STATUS_PURGED then the memory is present but any | 114 // DISCARDABLE_MEMORY_LOCK_STATUS_PURGED then the memory is present but any |
105 // data that was in it is gone. | 115 // data that was in it is gone. |
106 virtual DiscardableMemoryLockStatus Lock() WARN_UNUSED_RESULT = 0; | 116 virtual DiscardableMemoryLockStatus Lock() WARN_UNUSED_RESULT = 0; |
107 | 117 |
108 // Unlocks the memory so that it can be purged by the system. Must be called | 118 // Unlocks the memory so that it can be purged by the system. Must be called |
109 // after every successful lock call. | 119 // after every successful lock call. |
110 virtual void Unlock() = 0; | 120 virtual void Unlock() = 0; |
111 | 121 |
112 // Returns the memory address held by this object. The object must be locked | 122 // Returns the memory address held by this object. The object must be locked |
113 // before calling this. Otherwise, this will cause a DCHECK error. | 123 // before calling this. Otherwise, this will cause a DCHECK error. |
114 virtual void* Memory() const = 0; | 124 virtual void* Memory() const = 0; |
115 | 125 |
116 // Testing utility calls. | 126 // Testing utility calls. |
117 | 127 |
118 // Purge all discardable memory in the system. This call has global effects | 128 // Purge all discardable memory in the system. This call has global effects |
119 // across all running processes, so it should only be used for testing! | 129 // across all running processes, so it should only be used for testing! |
120 static void PurgeForTesting(); | 130 static void PurgeForTesting(); |
121 }; | 131 }; |
122 | 132 |
123 } // namespace base | 133 } // namespace base |
124 | 134 |
125 #endif // BASE_MEMORY_DISCARDABLE_MEMORY_H_ | 135 #endif // BASE_MEMORY_DISCARDABLE_MEMORY_H_ |
OLD | NEW |