1 // Copyright 2024 The Pigweed Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not 4 // use this file except in compliance with the License. You may obtain a copy of 5 // the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations under 13 // the License. 14 15 #include "pw_allocator/bucket_block_allocator.h" 16 17 #include "pw_malloc/config.h" 18 #include "pw_malloc/malloc.h" 19 20 namespace pw::malloc { 21 namespace { 22 23 using BucketBlockAllocator = 24 ::pw::allocator::BucketBlockAllocator<PW_MALLOC_BLOCK_OFFSET_TYPE, 25 PW_MALLOC_MIN_BUCKET_SIZE, 26 PW_MALLOC_NUM_BUCKETS, 27 PW_MALLOC_BLOCK_POISON_INTERVAL, 28 PW_MALLOC_BLOCK_ALIGNMENT>; 29 GetBucketBlockAllocator()30BucketBlockAllocator& GetBucketBlockAllocator() { 31 static BucketBlockAllocator allocator; 32 return allocator; 33 } 34 35 } // namespace 36 GetSystemAllocator()37Allocator* GetSystemAllocator() { 38 auto& system_allocator = GetBucketBlockAllocator(); 39 return &system_allocator; 40 } 41 InitSystemAllocator(ByteSpan heap)42void InitSystemAllocator(ByteSpan heap) { 43 auto& system_allocator = GetBucketBlockAllocator(); 44 system_allocator.Init(heap); 45 } 46 47 } // namespace pw::malloc 48