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

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: Address reviewers' comments 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
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_

Powered by Google App Engine
This is Rietveld 408576698