Pigweed
 
Loading...
Searching...
No Matches
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 <cstddef>
17#include <cstdint>
18
19#include "pw_allocator/capability.h"
20#include "pw_allocator/deallocator.h"
21#include "pw_allocator/layout.h"
22#include "pw_bytes/span.h"
23#include "pw_result/result.h"
24
25namespace pw::allocator {
26
32class Pool : public Deallocator {
33 public:
34 constexpr Pool(const Capabilities& capabilities, const Layout& layout)
35 : Deallocator(capabilities), layout_(layout) {}
36
37 const Layout& layout() const { return layout_; }
38
44 void* Allocate() { return DoAllocate(); }
45
46 private:
48 virtual void* DoAllocate() = 0;
49
50 const Layout layout_;
51};
52
53} // namespace pw::allocator
Abstract interface for releasing memory.
Definition: deallocator.h:26
constexpr Deallocator()=default
TODO(b/326509341): Remove when downstream consumers migrate.
Definition: capability.h:62
Definition: layout.h:56
Definition: pool.h:32
void * Allocate()
Definition: pool.h:44
virtual void * DoAllocate()=0
Virtual Allocate function that can be overridden by derived classes.