C/C++ API Reference
Loading...
Searching...
No Matches
single_chunk_region_tracker.h
1// Copyright 2025 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#pragma once
15
16#include <atomic>
17#include <cstddef>
18#include <optional>
19
20#include "pw_allocator/allocator.h"
21#include "pw_allocator/block/tiny_block.h"
22#include "pw_allocator/first_fit.h"
23#include "pw_allocator/layout.h"
24// #include "pw_allocator/typed_pool.h"
25#include "pw_bytes/span.h"
26#include "pw_containers/storage.h"
27#include "pw_multibuf/v1_adapter/chunk.h"
28#include "pw_multibuf/v1_adapter/internal/chunk_allocator.h"
29#include "pw_multibuf/v2/internal/entry.h"
30
31namespace pw::multibuf::v1_adapter {
32
34
41 public:
42 explicit SingleChunkRegionTracker(ByteSpan region)
43 : metadata_allocator_(metadata_buffer_),
44 allocator_(region, metadata_allocator_) {}
45
47 std::optional<OwnedChunk> GetChunk(size_t size) {
48 return allocator_.AllocateChunk(size);
49 }
50
51 private:
53 static constexpr size_t kBufSize = sizeof(v2::internal::Entry) * 32;
54
55 std::array<std::byte, kBufSize> metadata_buffer_{};
56
58
59 internal::SingleChunkAllocator allocator_;
60};
61
63
64} // namespace pw::multibuf::v1_adapter
Definition: first_fit.h:41
Definition: single_chunk_region_tracker.h:40
std::optional< OwnedChunk > GetChunk(size_t size)
Definition: single_chunk_region_tracker.h:47
Definition: entry.h:47