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

Unified Diff: base/memory/discardable_memory_allocator.h

Issue 25293002: Add DiscardableMemoryAllocator to work around FD limit issue. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Shorten critical section + add unit test Created 7 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/memory/discardable_memory.cc ('k') | base/memory/discardable_memory_allocator.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..a2002420981f4c9e32090ae147139db26f712e11
--- /dev/null
+++ b/base/memory/discardable_memory_allocator.h
@@ -0,0 +1,48 @@
+// Copyright (c) 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.
+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);
+
+ // Returns an allocator instance that can be used on any thread. Note that
+ // this doesn't change the fact that allocated DiscardableMemory instances are
+ // not thread-safe (i.e. only the allocator is).
+ static scoped_ptr<DiscardableMemoryAllocator> CreateThreadSafeInstance(
+ 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_
« no previous file with comments | « base/memory/discardable_memory.cc ('k') | base/memory/discardable_memory_allocator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698