diff --git a/CMakeLists.txt b/CMakeLists.txt index 2dd503d..0d7051d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.25) -project(blt-gp VERSION 0.1.9) +project(blt-gp VERSION 0.1.12) include(CTest) diff --git a/include/blt/gp/stack.h b/include/blt/gp/stack.h index da808a3..7d4e5df 100644 --- a/include/blt/gp/stack.h +++ b/include/blt/gp/stack.h @@ -20,6 +20,7 @@ #define BLT_GP_STACK_H #include +#include #include #include #include @@ -42,13 +43,29 @@ namespace blt::gp BLT_META_MAKE_FUNCTION_CHECK(drop); } + class aligned_allocator + { + public: + void* allocate(blt::size_t bytes) // NOLINT + { + return std::aligned_alloc(8, bytes); + } + + void deallocate(void* ptr, blt::size_t) // NOLINT + { + std::free(ptr); + } + }; + class stack_allocator { constexpr static blt::size_t PAGE_SIZE = 0x1000; constexpr static blt::size_t MAX_ALIGNMENT = 8; template using NO_REF_T = std::remove_cv_t>; + using Allocator = aligned_allocator; public: + static Allocator& get_allocator(); struct size_data_t { blt::size_t total_size_bytes = 0; @@ -104,7 +121,8 @@ namespace blt::gp ~stack_allocator() { - std::free(data_); + //std::free(data_); + get_allocator().deallocate(data_, size_); } void insert(const stack_allocator& stack) @@ -252,10 +270,12 @@ namespace blt::gp void expand(blt::size_t bytes) { bytes = to_nearest_page_size(bytes); - auto new_data = static_cast(std::malloc(bytes)); +// auto new_data = static_cast(std::malloc(bytes)); + auto new_data = static_cast(get_allocator().allocate(bytes)); if (bytes_stored > 0) std::memcpy(new_data, data_, bytes_stored); - std::free(data_); +// std::free(data_); + get_allocator().deallocate(data_, size_); data_ = new_data; size_ = bytes; } @@ -310,6 +330,8 @@ namespace blt::gp blt::size_t bytes_stored = 0; blt::size_t size_ = 0; }; + + } #endif //BLT_GP_STACK_H diff --git a/lib/blt b/lib/blt index 9799040..72211e3 160000 --- a/lib/blt +++ b/lib/blt @@ -1 +1 @@ -Subproject commit 97990401e2332276b5397060a3ccaf19f07fb999 +Subproject commit 72211e3d7b29cec887257d59578669f198c2d3da diff --git a/src/program.cpp b/src/program.cpp index 9f4b023..b5e01be 100644 --- a/src/program.cpp +++ b/src/program.cpp @@ -50,6 +50,12 @@ namespace blt::gp return random_engine; } + stack_allocator::Allocator& stack_allocator::get_allocator() + { + thread_local static Allocator allocator; + return allocator; + } + void gp_program::create_threads() { if (config.threads == 0)