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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/memory/discardable_memory.cc ('k') | base/memory/discardable_memory_allocator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
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 class BASE_EXPORT DiscardableMemoryAllocator {
29 public:
30 virtual ~DiscardableMemoryAllocator() {}
31
32 // Note that |name| is only used for debugging/measurement purposes.
33 static scoped_ptr<DiscardableMemoryAllocator> Create(const std::string& name);
34
35 // Returns an allocator instance that can be used on any thread. Note that
36 // this doesn't change the fact that allocated DiscardableMemory instances are
37 // not thread-safe (i.e. only the allocator is).
38 static scoped_ptr<DiscardableMemoryAllocator> CreateThreadSafeInstance(
39 const std::string& name);
40
41 // Note that the allocator must outlive the returned DiscardableMemory
42 // instance.
43 virtual scoped_ptr<DiscardableMemory> Allocate(size_t size) = 0;
44 };
45
46 } // namespace base
47
48 #endif // BASE_MEMORY_DISCARDABLE_MEMORY_ALLOCATOR_H_
OLDNEW
« 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