OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef BASE_MEMORY_DISCARDABLE_MEMORY_ALLOCATOR_H_ |
| 6 #define BASE_MEMORY_DISCARDABLE_MEMORY_ALLOCATOR_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/base_export.h" |
| 11 #include "base/basictypes.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 |
| 14 namespace base { |
| 15 |
| 16 class DiscardableMemory; |
| 17 |
| 18 // Allows multiple pieces of discardable memory to be allocated by efficiently |
| 19 // managing resources. |
| 20 // On certain platforms such as Android, discardable memory is backed by a file |
| 21 // (descriptor) thus is a limited resource. This allocator minimizes the problem |
| 22 // by operating on large pieces of memory and returning to the client chunks in |
| 23 // it. |
| 24 // Allocated chunks are systematically aligned on a page boundary therefore this |
| 25 // allocator is not recommended for clients performing (a lot of) small |
| 26 // allocations. This can be useful for instance for clients implementing large |
| 27 // resource in-memory caches. |
| 28 // |
| 29 // Thread-safety: |
| 30 // The allocator must be deleted on the thread it was constructed on although |
| 31 // its Allocate() method can be invoked on any thread. See discardable_memory.h |
| 32 // for DiscardableMemory's threading guarantees. |
| 33 class BASE_EXPORT DiscardableMemoryAllocator { |
| 34 public: |
| 35 virtual ~DiscardableMemoryAllocator() {} |
| 36 |
| 37 // Note that |name| is only used for debugging/measurement purposes. |
| 38 static scoped_ptr<DiscardableMemoryAllocator> Create(const std::string& name); |
| 39 |
| 40 // Note that the allocator must outlive the returned DiscardableMemory |
| 41 // instance. |
| 42 virtual scoped_ptr<DiscardableMemory> Allocate(size_t size) = 0; |
| 43 }; |
| 44 |
| 45 } // namespace base |
| 46 |
| 47 #endif // BASE_MEMORY_DISCARDABLE_MEMORY_ALLOCATOR_H_ |
OLD | NEW |