diff --git a/src/modm/communication/rpr/interface.hpp b/src/modm/communication/rpr/interface.hpp index 14f65a82b8..b39c401535 100644 --- a/src/modm/communication/rpr/interface.hpp +++ b/src/modm/communication/rpr/interface.hpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include "constants.hpp" @@ -123,7 +123,7 @@ namespace modm static Queue messagesToSend; static Queue receivedMessages; - static modm::allocator::Dynamic bufferAllocator; + static std::allocator bufferAllocator; static Message receiveBuffer; static uint8_t rx_buffer[N+8]; diff --git a/src/modm/communication/rpr/interface_impl.hpp b/src/modm/communication/rpr/interface_impl.hpp index 6af92dcff0..baadeb638f 100644 --- a/src/modm/communication/rpr/interface_impl.hpp +++ b/src/modm/communication/rpr/interface_impl.hpp @@ -472,7 +472,7 @@ modm::rpr::Interface::popMessage(Queue &queue) // deallocate the external buffer Message message = queue.get(); MODM_RPR_LOG("deallocating"); - bufferAllocator.deallocate(message.payload); + bufferAllocator.deallocate(message.payload, 1); // then remove the rest queue.pop(); } diff --git a/src/modm/container/doubly_linked_list.hpp b/src/modm/container/doubly_linked_list.hpp index ecd73abb61..735af8062d 100644 --- a/src/modm/container/doubly_linked_list.hpp +++ b/src/modm/container/doubly_linked_list.hpp @@ -17,7 +17,7 @@ #define MODM_DOUBLY_LINKED_LIST_HPP #include -#include +#include #include namespace modm @@ -30,7 +30,7 @@ namespace modm * \author Fabian Greif * \ingroup modm_container */ - template > + template > class DoublyLinkedList { public: @@ -91,7 +91,7 @@ namespace modm // rebind the type to Allocator>. Node is not the same // size as T (it's one pointer larger), and specializations on T may go // unused because Node is being bound instead. - typedef typename Allocator::template rebind< Node >::other NodeAllocator; + using NodeAllocator = typename std::allocator_traits::template rebind_alloc; NodeAllocator nodeAllocator; diff --git a/src/modm/container/doubly_linked_list_impl.hpp b/src/modm/container/doubly_linked_list_impl.hpp index b386e79393..54e1899c75 100644 --- a/src/modm/container/doubly_linked_list_impl.hpp +++ b/src/modm/container/doubly_linked_list_impl.hpp @@ -33,8 +33,8 @@ modm::DoublyLinkedList::~DoublyLinkedList() Node *node = this->front; this->front = this->front->next; - Allocator::destroy(&node->value); - this->nodeAllocator.deallocate(node); + std::destroy_at(&node->value); + this->nodeAllocator.deallocate(node, 1); } } @@ -63,7 +63,7 @@ modm::DoublyLinkedList::prepend(const T& value) { // allocate memory for the new node and copy the value into it Node *node = this->nodeAllocator.allocate(1); - Allocator::construct(&node->value, value); + std::construct_at(&node->value, value); // hook the node into the list node->next = this->front; @@ -88,7 +88,7 @@ modm::DoublyLinkedList::append(const T& value) { // allocate memory for the new node and copy the value into it Node *node = this->nodeAllocator.allocate(1); - Allocator::construct(&node->value, value); + std::construct_at(&node->value, value); // hook the node into the list node->next = 0; @@ -125,8 +125,8 @@ modm::DoublyLinkedList::removeFront() } // call destructor and free memory - Allocator::destroy(&node->value); - this->nodeAllocator.deallocate(node); + std::destroy_at(&node->value); + this->nodeAllocator.deallocate(node, 1); } template @@ -148,8 +148,8 @@ modm::DoublyLinkedList::removeBack() } // call destructor and free memory - Allocator::destroy(&node->value); - this->nodeAllocator.deallocate(node); + std::destroy_at(&node->value); + this->nodeAllocator.deallocate(node, 1); } // ---------------------------------------------------------------------------- @@ -216,8 +216,8 @@ modm::DoublyLinkedList::erase(iterator position) Node* next = position.node->next; - Allocator::destroy(&(position.node->value)); - this->nodeAllocator.deallocate(position.node); + std::destroy_at(&(position.node->value)); + this->nodeAllocator.deallocate(position.node, 1); return iterator(next); diff --git a/src/modm/container/dynamic_array.hpp b/src/modm/container/dynamic_array.hpp index 24b1b1a615..529d96a3b4 100644 --- a/src/modm/container/dynamic_array.hpp +++ b/src/modm/container/dynamic_array.hpp @@ -17,7 +17,7 @@ #define MODM_DYNAMIC_ARRAY_HPP #include -#include +#include #include #include @@ -44,7 +44,7 @@ namespace modm * \author Fabian Greif * \ingroup modm_container */ - template > + template > class DynamicArray { public: diff --git a/src/modm/container/dynamic_array_impl.hpp b/src/modm/container/dynamic_array_impl.hpp index 544764456a..15899e9206 100644 --- a/src/modm/container/dynamic_array_impl.hpp +++ b/src/modm/container/dynamic_array_impl.hpp @@ -38,7 +38,7 @@ modm::DynamicArray::DynamicArray(SizeType n, const T& value, const { this->values = this->allocator.allocate(n); for (SizeType i = 0; i < n; ++i) { - allocator.construct(&this->values[i], value); + std::construct_at(&this->values[i], value); } } @@ -49,7 +49,7 @@ modm::DynamicArray::DynamicArray(std::initializer_list init, co this->values = this->allocator.allocate(init.size()); std::size_t ii = 0; for (auto value : init) { - allocator.construct(&this->values[ii], value); + std::construct_at(&this->values[ii], value); ++ii; } } @@ -61,7 +61,7 @@ modm::DynamicArray::DynamicArray(const DynamicArray& other) : { this->values = allocator.allocate(other.capacity); for (SizeType i = 0; i < this->size; ++i) { - this->allocator.construct(&this->values[i], other.values[i]); + std::construct_at(&this->values[i], other.values[i]); } } @@ -69,9 +69,9 @@ template modm::DynamicArray::~DynamicArray() { for (SizeType i = 0; i < this->size; ++i) { - this->allocator.destroy(&this->values[i]); + std::destroy_at(&this->values[i]); } - this->allocator.deallocate(this->values); + this->allocator.deallocate(this->values, 1); } template @@ -79,9 +79,9 @@ modm::DynamicArray& modm::DynamicArray::operator = (const DynamicArray& other) { for (SizeType i = 0; i < this->size; ++i) { - this->allocator.destroy(&this->values[i]); + std::destroy_at(&this->values[i]); } - this->allocator.deallocate(this->values); + this->allocator.deallocate(this->values, 1); this->allocator = other.allocator; this->size = other.size; @@ -89,7 +89,7 @@ modm::DynamicArray::operator = (const DynamicArray& other) this->values = this->allocator.allocate(this->capacity); for (SizeType i = 0; i < this->size; ++i) { - this->allocator.construct(&this->values[i], other.values[i]); + std::construct_at(&this->values[i], other.values[i]); } return *this; } @@ -114,9 +114,9 @@ void modm::DynamicArray::clear() { for (SizeType i = 0; i < this->size; ++i) { - this->allocator.destroy(&this->values[i]); + std::destroy_at(&this->values[i]); } - this->allocator.deallocate(this->values); + this->allocator.deallocate(this->values, 1); this->values = 0; this->size = 0; @@ -129,7 +129,7 @@ void modm::DynamicArray::removeAll() { for (SizeType i = 0; i < this->size; ++i) { - this->allocator.destroy(&this->values[i]); + std::destroy_at(&this->values[i]); } this->size = 0; } @@ -149,7 +149,7 @@ modm::DynamicArray::append(const T& value) this->relocate(n); } - this->allocator.construct(&this->values[this->size], value); + std::construct_at(&this->values[this->size], value); ++this->size; } @@ -161,7 +161,7 @@ modm::DynamicArray::removeBack() --this->size; // call destructor - this->allocator.destroy(&this->values[this->size]); + std::destroy_at(&this->values[this->size]); } // ---------------------------------------------------------------------------- @@ -173,10 +173,10 @@ modm::DynamicArray::relocate(SizeType n) T* newBuffer = allocator.allocate(n); for (SizeType i = 0; i < this->size; ++i) { - this->allocator.construct(&newBuffer[i], this->values[i]); - this->allocator.destroy(&this->values[i]); + std::construct_at(&newBuffer[i], this->values[i]); + std::destroy_at(&this->values[i]); } - this->allocator.deallocate(this->values); + this->allocator.deallocate(this->values, 1); this->values = newBuffer; } diff --git a/src/modm/container/linked_list.hpp b/src/modm/container/linked_list.hpp index 2cb57e0fa9..d13561a138 100644 --- a/src/modm/container/linked_list.hpp +++ b/src/modm/container/linked_list.hpp @@ -18,7 +18,7 @@ #include #include -#include +#include namespace modm { @@ -29,13 +29,12 @@ namespace modm * \todo implementation * * \tparam T Type of list entries - * \tparam Allocator Allocator used for memory allocation. See - * classes from modm::allocator namespace. + * \tparam Allocator Allocator used for memory allocation. * * \author Fabian Greif * \ingroup modm_container */ - template > + template > class LinkedList { public: @@ -106,7 +105,7 @@ namespace modm // rebind the type to Allocator>. Node is not the same // size as T (it's one pointer larger), and specializations on T may go // unused because Node is being bound instead. - typedef typename Allocator::template rebind< Node >::other NodeAllocator; + using NodeAllocator = typename std::allocator_traits::template rebind_alloc; NodeAllocator nodeAllocator; diff --git a/src/modm/container/linked_list_impl.hpp b/src/modm/container/linked_list_impl.hpp index 7716879fb4..2d66a3d6a6 100644 --- a/src/modm/container/linked_list_impl.hpp +++ b/src/modm/container/linked_list_impl.hpp @@ -33,8 +33,8 @@ modm::LinkedList::~LinkedList() Node *node = this->front; this->front = this->front->next; - Allocator::destroy(&node->value); - this->nodeAllocator.deallocate(node); + std::destroy_at(&node->value); + this->nodeAllocator.deallocate(node, 1); } } @@ -63,7 +63,7 @@ modm::LinkedList::prepend(const T& value) { // allocate memory for the new node and copy the value into it Node *node = this->nodeAllocator.allocate(1); - Allocator::construct(&node->value, value); + std::construct_at(&node->value, value); // hook the node into the list node->next = this->front; @@ -83,7 +83,7 @@ modm::LinkedList::append(const T& value) { // allocate memory for the new node and copy the value into it Node *node = this->nodeAllocator.allocate(1); - Allocator::construct(&node->value, value); + std::construct_at(&node->value, value); // hook the node into the list node->next = 0; @@ -111,7 +111,7 @@ modm::LinkedList::insert(const_iterator pos, const T& value) // allocate memory for the new node and copy the value into it Node *node = this->nodeAllocator.allocate(1); - Allocator::construct(&node->value, value); + std::construct_at(&node->value, value); // hook the node into the list node->next = pos.node->next; @@ -141,8 +141,8 @@ modm::LinkedList::removeFront() } // call destructor and free memory - Allocator::destroy(&node->value); - this->nodeAllocator.deallocate(node); + std::destroy_at(&node->value); + this->nodeAllocator.deallocate(node, 1); } // ---------------------------------------------------------------------------- @@ -209,8 +209,8 @@ modm::LinkedList::remove(const iterator& iter) node->next = iter.node->next; // call destructor and free memory - Allocator::destroy(&iter.node->value); - this->nodeAllocator.deallocate(iter.node); + std::destroy_at(&iter.node->value); + this->nodeAllocator.deallocate(iter.node, 1); return iterator(node->next); } diff --git a/src/modm/container/module.lb b/src/modm/container/module.lb index 1c8b679fa3..4b780df676 100644 --- a/src/modm/container/module.lb +++ b/src/modm/container/module.lb @@ -20,8 +20,7 @@ def init(module): def prepare(module, options): module.depends( ":architecture", - ":io", - ":utils") + ":io") return True diff --git a/src/modm/utils/allocator.hpp b/src/modm/utils/allocator.hpp index 880220a3e4..2f0b1dd043 100644 --- a/src/modm/utils/allocator.hpp +++ b/src/modm/utils/allocator.hpp @@ -19,12 +19,14 @@ namespace modm::allocator { +// DEPRECATED: 2025q3 /** * Base class for all allocator types * * @ingroup modm_utils * @author Fabian Greif */ +[[deprecated("Please use std::allocator instead!")]] template class AllocatorBase { @@ -66,6 +68,7 @@ class AllocatorBase } }; +// DEPRECATED: 2025q3 /** * Dynamic memory allocator * @@ -75,6 +78,7 @@ class AllocatorBase * @ingroup modm_utils * @author Fabian Greif */ +[[deprecated("Please use std::allocator instead!")]] template class Dynamic : public AllocatorBase {