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

Side by Side Diff: base/memory/discardable_memory.h

Issue 935333002: Update from https://crrev.com/316786 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « base/macros.h ('k') | base/memory/discardable_memory_android.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 // Gets the preferred discardable memory type. 82 // Gets the preferred discardable memory type.
83 static DiscardableMemoryType GetPreferredType(); 83 static DiscardableMemoryType GetPreferredType();
84 84
85 // Create a DiscardableMemory instance with specified |type| and |size|. 85 // Create a DiscardableMemory instance with specified |type| and |size|.
86 static scoped_ptr<DiscardableMemory> CreateLockedMemoryWithType( 86 static scoped_ptr<DiscardableMemory> CreateLockedMemoryWithType(
87 DiscardableMemoryType type, size_t size); 87 DiscardableMemoryType type, size_t size);
88 88
89 // Create a DiscardableMemory instance with preferred type and |size|. 89 // Create a DiscardableMemory instance with preferred type and |size|.
90 static scoped_ptr<DiscardableMemory> CreateLockedMemory(size_t size); 90 static scoped_ptr<DiscardableMemory> CreateLockedMemory(size_t size);
91 91
92 // Discardable memory implementations might use this to release memory
93 // or resources assigned to instances that have been purged.
94 static void ReleaseFreeMemory();
95
96 // Discardable memory implementations might allow an elevated usage level 92 // Discardable memory implementations might allow an elevated usage level
97 // while in frequent use. Call this to have the usage reduced to the base 93 // while in frequent use. Call this to have the usage reduced to the base
98 // level. Returns true if there's no need to call this again until 94 // level. Returns true if there's no need to call this again until
99 // memory instances have been used. This indicates that all discardable 95 // memory instances have been used. This indicates that all discardable
100 // memory implementations have reduced usage to the base level or below. 96 // memory implementations have reduced usage to the base level or below.
101 // Note: calling this too often or while discardable memory is in frequent 97 // Note: calling this too often or while discardable memory is in frequent
102 // use can hurt performance, whereas calling it too infrequently can result 98 // use can hurt performance, whereas calling it too infrequently can result
103 // in memory bloat. 99 // in memory bloat.
104 static bool ReduceMemoryUsage(); 100 static bool ReduceMemoryUsage();
105 101
106 // Locks the memory so that it will not be purged by the system. Returns 102 // Locks the memory so that it will not be purged by the system. Returns
107 // DISCARDABLE_MEMORY_LOCK_STATUS_SUCCESS on success. If the return value is 103 // DISCARDABLE_MEMORY_LOCK_STATUS_SUCCESS on success. If the return value is
108 // DISCARDABLE_MEMORY_LOCK_STATUS_FAILED then this object should be 104 // DISCARDABLE_MEMORY_LOCK_STATUS_FAILED then this object should be
109 // discarded and a new one should be created. If the return value is 105 // discarded and a new one should be created. If the return value is
110 // DISCARDABLE_MEMORY_LOCK_STATUS_PURGED then the memory is present but any 106 // DISCARDABLE_MEMORY_LOCK_STATUS_PURGED then the memory is present but any
111 // data that was in it is gone. 107 // data that was in it is gone.
112 virtual DiscardableMemoryLockStatus Lock() WARN_UNUSED_RESULT = 0; 108 virtual DiscardableMemoryLockStatus Lock() WARN_UNUSED_RESULT = 0;
113 109
114 // Unlocks the memory so that it can be purged by the system. Must be called 110 // Unlocks the memory so that it can be purged by the system. Must be called
115 // after every successful lock call. 111 // after every successful lock call.
116 virtual void Unlock() = 0; 112 virtual void Unlock() = 0;
117 113
118 // Returns the memory address held by this object. The object must be locked 114 // Returns the memory address held by this object. The object must be locked
119 // before calling this. Otherwise, this will cause a DCHECK error. 115 // before calling this. Otherwise, this will cause a DCHECK error.
120 virtual void* Memory() const = 0; 116 virtual void* Memory() const = 0;
121
122 // Testing utility calls.
123
124 // Purge all discardable memory in the system. This call has global effects
125 // across all running processes, so it should only be used for testing!
126 static void PurgeForTesting();
127 }; 117 };
128 118
129 } // namespace base 119 } // namespace base
130 120
131 #endif // BASE_MEMORY_DISCARDABLE_MEMORY_H_ 121 #endif // BASE_MEMORY_DISCARDABLE_MEMORY_H_
OLDNEW
« no previous file with comments | « base/macros.h ('k') | base/memory/discardable_memory_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698