34#pragma clang diagnostic ignored "-Wc++98-compat"
51#pragma GCC diagnostic push
52#pragma GCC diagnostic ignored "-Wunused-parameter"
57 assert(bytes <= block_size_bytes_);
59 if (first_ ==
nullptr)
64 void* p =
static_cast<void*
> (first_);
65 first_ = *(
static_cast<void**
> (first_));
67#pragma GCC diagnostic push
69#pragma clang diagnostic ignored "-Wdeprecated-volatile"
72#pragma GCC diagnostic pop
78#if defined(OS_TRACE_LIBCPP_MEMORY_RESOURCE)
79 trace::printf (
"%s(%u,%u)=%p,%u @%p %s\n", __func__, bytes, alignment, p,
80 block_size_bytes_,
this,
name ());
88 std::size_t alignment)
noexcept
90#if defined(OS_TRACE_LIBCPP_MEMORY_RESOURCE)
91 trace::printf (
"%s(%p,%u,%u) @%p %s\n", __func__, addr, bytes, alignment,
95 if ((addr < pool_addr_)
97 >= (
static_cast<char*
> (pool_addr_) + blocks_ * block_size_bytes_)))
108 *(
static_cast<void**
> (addr)) = first_;
113#pragma GCC diagnostic push
114#if defined(__clang__)
115#pragma clang diagnostic ignored "-Wdeprecated-volatile"
118#pragma GCC diagnostic pop
122 internal_decrease_allocated_statistics (block_size_bytes_);
125#pragma GCC diagnostic push
130 return block_size_bytes_ * blocks_;
136#if defined(OS_TRACE_LIBCPP_MEMORY_RESOURCE)
144 std::size_t block_size_bytes,
void* addr,
145 std::size_t bytes)
noexcept
151 assert(block_size_bytes_ >=
sizeof(
void*));
153 assert(addr !=
nullptr);
156 std::size_t align_sz = bytes;
160 res = std::align (
alignof(
void*), blocks * block_size_bytes_, pool_addr_,
166 assert(res !=
nullptr);
172 total_bytes_ = blocks_ * block_size_bytes_;
183 char* p =
static_cast<char*
> (pool_addr_);
184 for (std::size_t i = 1; i < blocks_; ++i)
187 char* pn = p + block_size_bytes_;
190 *(
static_cast<void**
> (
static_cast<void*
> (p))) = pn;
196 *(
static_cast<void**
> (
static_cast<void*
> (p))) =
nullptr;
202 allocated_bytes_ = 0;
203 max_allocated_bytes_ = 0;
204 free_bytes_ = total_bytes_;
205 allocated_chunks_ = 0;
206 free_chunks_ = blocks_;
virtual void * do_allocate(std::size_t bytes, std::size_t alignment) override
Implementation of the memory allocator.
virtual std::size_t do_max_size(void) const noexcept override
Implementation of the function to get max size.
void internal_construct_(std::size_t blocks, std::size_t block_size_bytes, void *addr, std::size_t bytes) noexcept
Internal function to construct the memory resource object instance.
virtual void do_deallocate(void *addr, std::size_t bytes, std::size_t alignment) noexcept override
Implementation of the memory deallocator.
void internal_reset_(void) noexcept
Internal function to reset the memory resource object.
virtual ~block_pool() override
Destruct the memory resource object instance.
virtual void do_reset(void) noexcept override
Implementation of the function to reset the memory manager.
const char * name(void) const
Get object name.
void internal_increase_allocated_statistics(std::size_t bytes) noexcept
Update statistics after allocation.
int printf(const char *format,...)
Write a formatted string to the trace device.
constexpr std::size_t align_size(std::size_t size, std::size_t align) noexcept
Helper function to align size values.
Single file µOS++ RTOS definitions.