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" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 // Locks the memory so that it will not be purged by the system. Returns | 45 // Locks the memory so that it will not be purged by the system. Returns |
46 // true on success. If the return value is false then this object should be | 46 // true on success. If the return value is false then this object should be |
47 // discarded and a new one should be created. | 47 // discarded and a new one should be created. |
48 virtual bool Lock() WARN_UNUSED_RESULT = 0; | 48 virtual bool Lock() WARN_UNUSED_RESULT = 0; |
49 | 49 |
50 // Unlocks the memory so that it can be purged by the system. Must be called | 50 // Unlocks the memory so that it can be purged by the system. Must be called |
51 // after every successful lock call. | 51 // after every successful lock call. |
52 virtual void Unlock() = 0; | 52 virtual void Unlock() = 0; |
53 | 53 |
54 // Returns the memory address held by this object. The object must be locked | 54 // Returns the memory address held by this object. The object must be locked |
55 // before calling this. Otherwise, this will cause a DCHECK error. | 55 // before calling this. |
56 virtual void* Memory() const = 0; | 56 virtual void* data() const = 0; |
| 57 |
| 58 // Handy method to simplify calling data() with a reinterpret_cast. |
| 59 template<typename T> const T* data_as() const { |
| 60 return reinterpret_cast<const T*>(data()); |
| 61 } |
57 }; | 62 }; |
58 | 63 |
59 } // namespace base | 64 } // namespace base |
60 | 65 |
61 #endif // BASE_MEMORY_DISCARDABLE_MEMORY_H_ | 66 #endif // BASE_MEMORY_DISCARDABLE_MEMORY_H_ |
OLD | NEW |