aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src/memory/allocator
diff options
context:
space:
mode:
authorMatteo Gmür <matteo.gmuer1@ost.ch>2024-10-27 09:21:25 +0000
committerMatteo Gmür <matteo.gmuer1@ost.ch>2024-10-27 09:21:25 +0000
commita29e823c6ead21fa7c8f6445411d52f57c4518fb (patch)
tree4e9b9d9fda793b9ecf680e57161c25a971b78f51 /arch/x86_64/src/memory/allocator
parentca17ed52ea768f1e1c837207f7d27afa6ed99cc2 (diff)
downloadkernel-a29e823c6ead21fa7c8f6445411d52f57c4518fb.tar.xz
kernel-a29e823c6ead21fa7c8f6445411d52f57c4518fb.zip
Attempt to start using C++20 algorithm calls.
Diffstat (limited to 'arch/x86_64/src/memory/allocator')
-rw-r--r--arch/x86_64/src/memory/allocator/area_frame_allocator.cpp24
1 files changed, 15 insertions, 9 deletions
diff --git a/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp b/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp
index c2cafce..c3f77e1 100644
--- a/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp
+++ b/arch/x86_64/src/memory/allocator/area_frame_allocator.cpp
@@ -2,13 +2,16 @@
#include "arch/exception_handling/assert.hpp"
+#include <algorithm>
+#include <array>
+#include <ranges>
+
namespace teachos::arch::memory::allocator
{
area_frame_allocator::area_frame_allocator(multiboot::memory_information mem_info)
: next_free_frame(0)
, current_area(std::nullopt)
- , area_begin(mem_info.memory_areas)
- , area_end(mem_info.memory_areas + mem_info.area_count)
+ , memory_areas(mem_info.memory_areas, mem_info.area_count)
, kernel_start(physical_frame::containing_address(mem_info.kernel_start))
, kernel_end(physical_frame::containing_address(mem_info.kernel_end))
, multiboot_start(physical_frame::containing_address(mem_info.multiboot_start))
@@ -21,10 +24,17 @@ namespace teachos::arch::memory::allocator
{
current_area = std::nullopt;
- for (multiboot::memory_area_iterator it = begin(); it != end(); ++it)
- {
- multiboot::memory_area & area = *it;
+ /**auto filtered_areas = memory_areas | std::views::filter([this](multiboot::memory_area area) {
+ auto address = area.base_address + area.area_length - 1;
+ return physical_frame::containing_address(address) >= next_free_frame;
+ });**/
+
+ std::ranges::min_element(memory_areas, [](multiboot::memory_area a, multiboot::memory_area b) {
+ return a.base_address < b.base_address;
+ });
+ for (auto area : memory_areas)
+ {
std::size_t address = area.base_address + area.area_length - 1;
if (physical_frame::containing_address(address) >= next_free_frame)
{
@@ -90,8 +100,4 @@ namespace teachos::arch::memory::allocator
exception_handling::assert(false && physical_frame.frame_number == 0,
"[deallocate_frame] Not implemented Exception");
}
-
- auto area_frame_allocator::begin() -> multiboot::memory_area_iterator { return area_begin; }
-
- auto area_frame_allocator::end() -> multiboot::memory_area_iterator { return area_end; }
} // namespace teachos::arch::memory::allocator