12#ifndef CMSIS_PLUS_MEMORY_MALLOC_H_
13#define CMSIS_PLUS_MEMORY_MALLOC_H_
17#if defined(__cplusplus)
21#if defined(OS_USE_OS_APP_CONFIG_H)
22#include <cmsis-plus/os-app-config.h>
29#pragma GCC diagnostic push
31#pragma clang diagnostic ignored "-Wc++98-compat"
41#pragma GCC diagnostic push
43#pragma clang diagnostic ignored "-Wweak-vtables"
118 do_allocate (std::size_t bytes, std::size_t alignment)
override;
130 std::size_t alignment)
noexcept override;
180 do_allocate (
size_t bytes,
size_t alignment)
override;
192 size_t alignment)
noexcept override;
199#pragma GCC diagnostic pop
220 : rtos::memory::memory_resource{ name }
222 trace::printf (
"%s() @%p %s\n", __func__,
this, this->name ());
230#pragma GCC diagnostic push
231#if defined(__clang__)
232#pragma clang diagnostic ignored "-Wunused-parameter"
233#elif defined(__GNUC__)
235#pragma GCC diagnostic ignored "-Wunused-parameter"
240 std::size_t alignment)
243 void* mem = std::malloc (bytes);
244#if defined(OS_TRACE_LIBCPP_MEMORY_RESOURCE)
245 trace::printf (
"%s(%u,%u)=%p @%p %s\n", __func__, bytes, alignment, mem,
254 std::size_t alignment)
noexcept
256#if defined(OS_TRACE_LIBCPP_MEMORY_RESOURCE)
257 trace::printf (
"%s(%p,%u,%u) @%p %s\n", __func__, addr, bytes, alignment,
264#pragma GCC diagnostic pop
268#pragma GCC diagnostic push
269#if defined(__clang__)
270#pragma clang diagnostic ignored "-Wunused-parameter"
271#elif defined(__GNUC__)
273#pragma GCC diagnostic ignored "-Wunused-parameter"
280 void* mem = ::operator
new (bytes);
281#if defined(OS_TRACE_LIBCPP_MEMORY_RESOURCE)
282 trace::printf (
"%s(%u,%u)=%p @%p %s\n", __func__, bytes, alignment, mem,
291 size_t alignment)
noexcept
293#if defined(OS_TRACE_LIBCPP_MEMORY_RESOURCE)
294 trace::printf (
"%s(%p,%u,%u) @%p %s\n", __func__, addr, bytes, alignment,
298 ::operator
delete (addr);
302#pragma GCC diagnostic pop
308#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.