|
7 | 7 | #include "arm_memory_allocator.h" |
8 | 8 |
|
9 | 9 | ArmMemoryAllocator::ArmMemoryAllocator(uint32_t size, uint8_t* base_address) |
10 | | - : MemoryAllocator(size, base_address), used_(0), peak_used_(0) {} |
| 10 | + : MemoryAllocator(size, base_address), used_(0), peak_used_(0) {} |
11 | 11 |
|
12 | | -void* ArmMemoryAllocator::allocate(size_t size, size_t alignment = kDefaultAlignment) override { |
13 | | - void* ret = executorch::runtime::MemoryAllocator::allocate(size, alignment); |
14 | | - if (ret != nullptr) { |
15 | | - // Align with the same code as in MemoryAllocator::allocate() to keep |
16 | | - // used_ "in sync" As alignment is expected to be power of 2 (checked by |
17 | | - // MemoryAllocator::allocate()) we can check it the lower bits |
18 | | - // (same as alignment - 1) is zero or not. |
19 | | - if ((size & (alignment - 1)) == 0) { |
20 | | - // Already aligned. |
21 | | - used_ += size; |
22 | | - } else { |
23 | | - used_ = (used_ | (alignment - 1)) + 1 + size; |
24 | | - } |
25 | | - if (used_ > peak_used_) |
26 | | - peak_used_ = used_; |
| 12 | +void* ArmMemoryAllocator::allocate( |
| 13 | + size_t size, |
| 14 | + size_t alignment = kDefaultAlignment) override { |
| 15 | + void* ret = executorch::runtime::MemoryAllocator::allocate(size, alignment); |
| 16 | + if (ret != nullptr) { |
| 17 | + // Align with the same code as in MemoryAllocator::allocate() to keep |
| 18 | + // used_ "in sync" As alignment is expected to be power of 2 (checked by |
| 19 | + // MemoryAllocator::allocate()) we can check it the lower bits |
| 20 | + // (same as alignment - 1) is zero or not. |
| 21 | + if ((size & (alignment - 1)) == 0) { |
| 22 | + // Already aligned. |
| 23 | + used_ += size; |
| 24 | + } else { |
| 25 | + used_ = (used_ | (alignment - 1)) + 1 + size; |
27 | 26 | } |
28 | | - return ret; |
| 27 | + if (used_ > peak_used_) |
| 28 | + peak_used_ = used_; |
| 29 | + } |
| 30 | + return ret; |
29 | 31 | } |
30 | 32 |
|
31 | 33 | size_t ArmMemoryAllocator::used_size() const { |
32 | | - return used_; |
| 34 | + return used_; |
33 | 35 | } |
34 | 36 |
|
35 | 37 | size_t ArmMemoryAllocator::peak_used() const { |
36 | | - return peak_used_; |
| 38 | + return peak_used_; |
37 | 39 | } |
38 | 40 |
|
39 | 41 | size_t ArmMemoryAllocator::free_size() const { |
40 | | - return executorch::runtime::MemoryAllocator::size() - used_; |
| 42 | + return executorch::runtime::MemoryAllocator::size() - used_; |
41 | 43 | } |
42 | 44 |
|
43 | 45 | void ArmMemoryAllocator::reset() { |
44 | | - executorch::runtime::MemoryAllocator::reset(); |
45 | | - used_ = 0; |
| 46 | + executorch::runtime::MemoryAllocator::reset(); |
| 47 | + used_ = 0; |
46 | 48 | } |
0 commit comments