OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 #include <gperftools/custom_allocator.h> |
| 6 |
| 7 #include "base/low_level_alloc.h" |
| 8 |
| 9 static LowLevelAlloc::Arena* g_arena = nullptr; |
| 10 |
| 11 // static |
| 12 void CustomAllocator::Initialize() { |
| 13 g_arena = LowLevelAlloc::NewArena(0, LowLevelAlloc::DefaultArena()); |
| 14 } |
| 15 |
| 16 // static |
| 17 bool CustomAllocator::Shutdown() { |
| 18 return LowLevelAlloc::DeleteArena(g_arena); |
| 19 } |
| 20 |
| 21 // static |
| 22 bool CustomAllocator::IsInitialized() { |
| 23 return g_arena; |
| 24 } |
| 25 |
| 26 // static |
| 27 void* CustomAllocator::Allocate(size_t size) { |
| 28 if (!g_arena) |
| 29 return nullptr; |
| 30 |
| 31 return LowLevelAlloc::AllocWithArena(size, g_arena); |
| 32 } |
| 33 |
| 34 // static |
| 35 void CustomAllocator::Free(void* ptr, size_t /* size */) { |
| 36 LowLevelAlloc::Free(ptr); |
| 37 } |
OLD | NEW |