Skip to content

Add make_monotonic_allocator<N>() #9

@kammce

Description

@kammce

Why

This will provide an easy way for developers to create allocators for their code and drivers that do not need deallocation support.

Usage

void initialize_platform() {
  auto driver_allocator = mem::make_monotonic_allocator<1024>();
  auto stm32f1 = hal::stm32f1::init(driver_allocator);
  // do the rest...
}

Function signature

template<size_t N>
monotonic_allocator make_monotonic_allocator();

Requirements

This monotonic allocator will differ from the standard one in the following ways:

  1. Stores memory internally such that the lifetime of the memory and the allocator are bound to each other.
  2. Will not have a fallback allocator, meaning if memory runs out, it will throw an exception that inherits from std::bad_alloc type.
  3. Will never deallocate memory, BUT records the total amount of deallocations. When the allocator's destructor is called, the allocation and deallocation amounts must be equal, otherwise std::terminate is called.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions