C/C++ API Reference
Loading...
Searching...
No Matches
malloc.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/allocator.h"
19#include "pw_bytes/span.h"
20#include "pw_malloc/config.h"
21#include "pw_preprocessor/util.h"
22
24namespace pw::malloc {
25
27
38
48void InitSystemAllocator(void* heap_low_addr, void* heap_high_addr);
49
57template <typename AllocatorType>
59
60} // namespace pw::malloc
61
62#if __cplusplus
63PW_EXTERN_C_START
64#endif
65
67void pw_MallocInit(uint8_t* heap_low_addr, uint8_t* heap_high_addr);
68
69#if __cplusplus
70PW_EXTERN_C_END
71#endif
72
73namespace pw::malloc {
74
89
104
105// Template method implementations.
106
107template <typename AllocatorType>
109 static bool initialized = false;
110 PW_ASSERT(!initialized);
111 auto* allocator = static_cast<AllocatorType*>(GetSystemAllocator());
112 allocator->Init(heap);
113 initialized = true;
114}
115
116} // namespace pw::malloc
Definition: allocator.h:36
const PW_MALLOC_METRICS_TYPE & UpdateSystemMetrics()
Allocator * GetSystemAllocator()
#define PW_MALLOC_METRICS_TYPE
Definition: config.h:36
void InitSystemAllocator(ByteSpan heap)
Replacement interface for standard libc dynamic memory operations.
Definition: malloc.h:24