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

Unified Diff: base/memory/discardable_memory_malloc.cc

Issue 145643008: base: Add uncached malloc based discardable memory type. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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_malloc.h ('k') | base/memory/discardable_memory_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/discardable_memory_malloc.cc
diff --git a/base/memory/discardable_memory_malloc.cc b/base/memory/discardable_memory_malloc.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d55135752698f5da21d189e1575aa3ea024819a4
--- /dev/null
+++ b/base/memory/discardable_memory_malloc.cc
@@ -0,0 +1,43 @@
+// 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.
+
+#include "base/memory/discardable_memory_malloc.h"
+
+#include "base/logging.h"
+
+namespace base {
+namespace internal {
+
+DiscardableMemoryMalloc::DiscardableMemoryMalloc(size_t size) : size_(size) {
+}
+
+DiscardableMemoryMalloc::~DiscardableMemoryMalloc() {
+}
+
+bool DiscardableMemoryMalloc::Initialize() {
+ return Lock() == DISCARDABLE_MEMORY_LOCK_STATUS_PURGED;
+}
+
+DiscardableMemoryLockStatus DiscardableMemoryMalloc::Lock() {
+ DCHECK(!memory_);
+
+ memory_.reset(static_cast<uint8*>(malloc(size_)));
+ if (!memory_)
+ return DISCARDABLE_MEMORY_LOCK_STATUS_FAILED;
+
+ return DISCARDABLE_MEMORY_LOCK_STATUS_PURGED;
+}
+
+void DiscardableMemoryMalloc::Unlock() {
+ DCHECK(memory_);
+ memory_.reset();
+}
+
+void* DiscardableMemoryMalloc::Memory() const {
+ DCHECK(memory_);
+ return memory_.get();
+}
+
+} // namespace internal
+} // namespace base
« no previous file with comments | « base/memory/discardable_memory_malloc.h ('k') | base/memory/discardable_memory_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698