| 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_
|
|
|