C/C++ API Reference
Loading...
Searching...
No Matches
chunk_pool.h
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#pragma once
15
16#include <cstdint>
17
18#include "pw_allocator/capability.h"
19#include "pw_allocator/layout.h"
20#include "pw_allocator/pool.h"
21#include "pw_bytes/span.h"
22#include "pw_status/status.h"
23
24namespace pw::allocator {
25
27
32class ChunkPool : public Pool {
33 public:
34 static constexpr Capabilities kCapabilities =
35 kImplementsGetRequestedLayout | kImplementsGetUsableLayout |
36 kImplementsGetAllocatedLayout | kImplementsGetCapacity |
37 kImplementsRecognizes;
38 static constexpr size_t kMinSize = sizeof(void*);
39 static constexpr size_t kMinAlignment = alignof(void*);
40
47 ChunkPool(ByteSpan region, const Layout& layout);
48
49 private:
51 void* DoAllocate() override;
52
54 void DoDeallocate(void* ptr) override;
55
57 Result<Layout> DoGetInfo(InfoType info_type, const void* ptr) const override;
58
59 const Layout allocated_layout_;
60 uintptr_t start_;
61 uintptr_t end_;
62 std::byte* next_;
63};
64
66
67} // namespace pw::allocator
Definition: poll.h:25
Definition: capability.h:64
Definition: chunk_pool.h:32
void DoDeallocate(void *ptr) override
ChunkPool(ByteSpan region, const Layout &layout)
Result< Layout > DoGetInfo(InfoType info_type, const void *ptr) const override
void * DoAllocate() override
Definition: layout.h:58
Definition: pool.h:35