13#ifndef CMSIS_PLUS_MEMORY_MALLOC_H_
14#define CMSIS_PLUS_MEMORY_MALLOC_H_
18#if defined(__cplusplus)
22#if defined(OS_USE_OS_APP_CONFIG_H)
23#include <cmsis-plus/os-app-config.h>
30#pragma GCC diagnostic push
32#pragma clang diagnostic ignored "-Wc++98-compat"
42#pragma GCC diagnostic push
44#pragma clang diagnostic ignored "-Wweak-vtables"
118 do_allocate (std::size_t bytes, std::size_t alignment)
override;
129 do_deallocate (
void* addr, std::size_t bytes, std::size_t alignment)
182 do_allocate (
size_t bytes,
size_t alignment)
override;
202#pragma GCC diagnostic pop
225 rtos::memory::memory_resource
228 trace::printf (
"%s() @%p %s\n", __func__,
this, this->name ());
237#pragma GCC diagnostic push
238#if defined(__clang__)
239#pragma clang diagnostic ignored "-Wunused-parameter"
240#elif defined(__GNUC__)
242#pragma GCC diagnostic ignored "-Wunused-parameter"
247 std::size_t alignment)
250 void* mem = std::malloc (bytes);
251#if defined(OS_TRACE_LIBCPP_MEMORY_RESOURCE)
252 trace::printf (
"%s(%u,%u)=%p @%p %s\n", __func__, bytes, alignment, mem,
261 std::size_t alignment)
noexcept
263#if defined(OS_TRACE_LIBCPP_MEMORY_RESOURCE)
264 trace::printf (
"%s(%p,%u,%u) @%p %s\n", __func__, addr, bytes, alignment,
271#pragma GCC diagnostic pop
275#pragma GCC diagnostic push
276#if defined(__clang__)
277#pragma clang diagnostic ignored "-Wunused-parameter"
278#elif defined(__GNUC__)
280#pragma GCC diagnostic ignored "-Wunused-parameter"
287 void* mem = ::operator
new (bytes);
288#if defined(OS_TRACE_LIBCPP_MEMORY_RESOURCE)
289 trace::printf (
"%s(%u,%u)=%p @%p %s\n", __func__, bytes, alignment, mem,
298 size_t alignment)
noexcept
300#if defined(OS_TRACE_LIBCPP_MEMORY_RESOURCE)
301 trace::printf (
"%s(%p,%u,%u) @%p %s\n", __func__, addr, bytes, alignment,
305 ::operator
delete (addr);
309#pragma GCC diagnostic pop
315#pragma GCC diagnostic pop
A memory manager that allocates memory via the system std::malloc() and deallocates via std::free().
malloc_memory_resource()
Default constructor. Construct a memory manager object instance.
virtual void do_deallocate(void *addr, std::size_t bytes, std::size_t alignment) noexcept override
Implementation of the memory deallocator.
virtual void * do_allocate(std::size_t bytes, std::size_t alignment) override
Implementation of the memory allocator.
~malloc_memory_resource() override
Destruct the memory manager object instance.
A memory manager that allocates memory via the system operator new and deallocates via operator delet...
~new_delete_memory_resource() override=default
Destruct the memory manager object instance.
virtual void * do_allocate(size_t bytes, size_t alignment) override
Implementation of the memory allocator.
virtual void do_deallocate(void *addr, size_t bytes, size_t alignment) noexcept override
Implementation of the memory deallocator.
const char * name(void) const
Get object name.
Memory resource manager (abstract class).
int printf(const char *format,...)
Write a formatted string to the trace device.
Single file µOS++ RTOS definitions.