1 // Copyright 2023 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 #pragma once 16 #include "pw_bluetooth_sapphire/internal/host/common/byte_buffer.h" 17 18 namespace bt { 19 20 // NOTE: Tweak these as needed. 21 constexpr size_t kSmallBufferSize = 64; 22 constexpr size_t kLargeBufferSize = 2048; 23 24 constexpr size_t kMaxNumSlabs = 100; 25 constexpr size_t kSlabSize = 32767; 26 27 // Returns a slab-allocated byte buffer with |size| bytes of capacity. The 28 // underlying allocation occupies |kSmallBufferSize| or |kLargeBufferSize| bytes 29 // of memory, unless: 30 // * |size| is 0, which returns a zero-sized byte buffer with no underlying 31 // slab allocation. 32 // * |size| exceeds |kLargeBufferSize|, which falls back to the system 33 // allocator. 34 // NOTE: In this case, if allocation fails, panic. 35 // 36 // Returns nullptr for failures to allocate. 37 [[nodiscard]] MutableByteBufferPtr NewBuffer(size_t size); 38 39 } // namespace bt 40