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([[maybe_unused]] void* ptr,
37 [[maybe_unused]] size_t new_size) override {
38 return false;
39 }
40
42 size_t DoGetAllocated() const override { return size_t(-1); }
43
45 std::optional<Fragmentation> DoMeasureFragmentation() const override {
46 return std::nullopt;
47 }
48
50 Result<Layout> DoGetInfo(InfoType, const void*) const override {
51 return Status::Unimplemented();
52 }
53};
54
56
57} // namespace pw::allocator
Definition: allocator.h:42
InfoType
Definition: deallocator.h:173
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:42
std::optional< Fragmentation > DoMeasureFragmentation() const override
Returns fragmentation information for the allocator's memory region.
Definition: abstract_allocator.h:45
Result< Layout > DoGetInfo(InfoType, const void *) const override
Definition: abstract_allocator.h:50
bool DoResize(void *ptr, size_t new_size) override
Definition: abstract_allocator.h:36
Definition: capability.h:65