Index: base/memory/discardable_memory_allocator.h |
diff --git a/base/memory/discardable_memory_allocator.h b/base/memory/discardable_memory_allocator.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b56bcc91c31218404c7c8b6c0346763f2a00ed70 |
--- /dev/null |
+++ b/base/memory/discardable_memory_allocator.h |
@@ -0,0 +1,47 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef BASE_MEMORY_DISCARDABLE_MEMORY_ALLOCATOR_H_ |
+#define BASE_MEMORY_DISCARDABLE_MEMORY_ALLOCATOR_H_ |
+ |
+#include <string> |
+ |
+#include "base/base_export.h" |
+#include "base/basictypes.h" |
+#include "base/memory/scoped_ptr.h" |
+ |
+namespace base { |
+ |
+class DiscardableMemory; |
+ |
+// Allows multiple pieces of discardable memory to be allocated by efficiently |
+// managing resources. |
+// On certain platforms such as Android, discardable memory is backed by a file |
+// (descriptor) thus is a limited resource. This allocator minimizes the problem |
+// by operating on large pieces of memory and returning to the client chunks in |
+// it. |
+// Allocated chunks are systematically aligned on a page boundary therefore this |
+// allocator is not recommended for clients performing (a lot of) small |
+// allocations. This can be useful for instance for clients implementing large |
+// resource in-memory caches. |
+// |
+// Thread-safety: |
+// The allocator must be deleted on the thread it was constructed on although |
+// its Allocate() method can be invoked on any thread. See discardable_memory.h |
+// for DiscardableMemory's threading guarantees. |
+class BASE_EXPORT DiscardableMemoryAllocator { |
+ public: |
+ virtual ~DiscardableMemoryAllocator() {} |
+ |
+ // Note that |name| is only used for debugging/measurement purposes. |
+ static scoped_ptr<DiscardableMemoryAllocator> Create(const std::string& name); |
+ |
+ // Note that the allocator must outlive the returned DiscardableMemory |
+ // instance. |
+ virtual scoped_ptr<DiscardableMemory> Allocate(size_t size) = 0; |
+}; |
+ |
+} // namespace base |
+ |
+#endif // BASE_MEMORY_DISCARDABLE_MEMORY_ALLOCATOR_H_ |