| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_BASE_ACCOUNTING_ALLOCATOR_H_ | 5 #ifndef V8_BASE_ACCOUNTING_ALLOCATOR_H_ |
| 6 #define V8_BASE_ACCOUNTING_ALLOCATOR_H_ | 6 #define V8_BASE_ACCOUNTING_ALLOCATOR_H_ |
| 7 | 7 |
| 8 #include "src/base/atomicops.h" | 8 #include "src/base/atomicops.h" |
| 9 #include "src/base/macros.h" | 9 #include "src/base/macros.h" |
| 10 | 10 |
| 11 namespace v8 { | 11 namespace v8 { |
| 12 namespace base { | 12 namespace base { |
| 13 | 13 |
| 14 class AccountingAllocator final { | 14 class AccountingAllocator final { |
| 15 public: | 15 public: |
| 16 AccountingAllocator() = default; | 16 AccountingAllocator() = default; |
| 17 ~AccountingAllocator() = default; | 17 ~AccountingAllocator() = default; |
| 18 | 18 |
| 19 // Returns nullptr on failed allocation. | 19 // Returns nullptr on failed allocation. |
| 20 void* Allocate(size_t bytes); | 20 void* Allocate(size_t bytes); |
| 21 void Free(void* memory, size_t bytes); | 21 void Free(void* memory, size_t bytes); |
| 22 | 22 |
| 23 size_t GetCurrentMemoryUsage() const; | 23 size_t GetCurrentMemoryUsage() const; |
| 24 size_t GetMaxMemoryUsage() const; |
| 24 | 25 |
| 25 private: | 26 private: |
| 26 AtomicWord current_memory_usage_ = 0; | 27 AtomicWord current_memory_usage_ = 0; |
| 28 AtomicWord max_memory_usage_ = 0; |
| 27 | 29 |
| 28 DISALLOW_COPY_AND_ASSIGN(AccountingAllocator); | 30 DISALLOW_COPY_AND_ASSIGN(AccountingAllocator); |
| 29 }; | 31 }; |
| 30 | 32 |
| 31 } // namespace base | 33 } // namespace base |
| 32 } // namespace v8 | 34 } // namespace v8 |
| 33 | 35 |
| 34 #endif // V8_BASE_ACCOUNTING_ALLOCATOR_H_ | 36 #endif // V8_BASE_ACCOUNTING_ALLOCATOR_H_ |
| OLD | NEW |