Pigweed
 
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
30class ChunkPool : public Pool {
31 public:
32 static constexpr Capabilities kCapabilities =
33 kImplementsGetRequestedLayout | kImplementsGetUsableLayout |
34 kImplementsGetAllocatedLayout | kImplementsGetCapacity |
35 kImplementsRecognizes;
36 static constexpr size_t kMinSize = sizeof(void*);
37 static constexpr size_t kMinAlignment = alignof(void*);
38
45 ChunkPool(ByteSpan region, const Layout& layout);
46
47 private:
49 void* DoAllocate() override;
50
52 void DoDeallocate(void* ptr) override;
53
55 Result<Layout> DoGetInfo(InfoType info_type, const void* ptr) const override;
56
57 const Layout allocated_layout_;
58 uintptr_t start_;
59 uintptr_t end_;
60 std::byte* next_;
61};
62
63} // namespace pw::allocator
Definition: capability.h:62
Definition: chunk_pool.h:30
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:56
Definition: pool.h:32