C/C++ API Reference
Loading...
Searching...
No Matches
abstract_allocator.h
1// Copyright 2026 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
18#include "pw_allocator/allocator.h"
19#include "pw_allocator/capability.h"
20
21namespace pw::allocator {
22
24
31 protected:
32 constexpr explicit AbstractAllocator(Capabilities capabilities)
33 : pw::Allocator(capabilities) {}
34
36 bool DoResize(void*, size_t) override { return false; }
37
39 size_t DoGetAllocated() const override { return size_t(-1); }
40
42 std::optional<Fragmentation> DoMeasureFragmentation() const override {
43 return std::nullopt;
44 }
45
47 Result<Layout> DoGetInfo(InfoType, const void*) const override {
48 return Status::Unimplemented();
49 }
50};
51
53
54} // namespace pw::allocator
Definition: allocator.h:42
Definition: result.h:145
static constexpr Status Unimplemented()
Definition: status.h:280
Definition: abstract_allocator.h:30
size_t DoGetAllocated() const override
Definition: abstract_allocator.h:39
std::optional< Fragmentation > DoMeasureFragmentation() const override
Returns fragmentation information for the allocator's memory region.
Definition: abstract_allocator.h:42
Result< Layout > DoGetInfo(InfoType, const void *) const override
Definition: abstract_allocator.h:47
bool DoResize(void *, size_t) override
Definition: abstract_allocator.h:36
Definition: capability.h:65