feat(Memory): add Memory subsystem with BudgetResource, Arena, and BlockPool (S-MEMORY-02..04)
This commit is contained in:
1 parent
4227348051
commit
4d48f2a8f2
11 files changed
+1306
No files matched your search
@@ -86,6 +86,11 @@ if(_has_core)
|
||||
run_consumer(CoreOnly "${install_prefix}" "CoreOnly" ${_no_external_deps})
|
||||
endif()
|
||||
|
||||
has_modules(_has_memory Memory Core)
|
||||
if(_has_memory)
|
||||
run_consumer(MemoryOnly "${install_prefix}" "MemoryOnly" ${_no_external_deps})
|
||||
endif()
|
||||
|
||||
has_modules(_has_binary Binary)
|
||||
if(_has_binary)
|
||||
run_consumer(Binary "${install_prefix}" "Binary" ${_no_external_deps})
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
cmake_minimum_required(VERSION 4.0)
|
||||
project(VoidMemoryOnlyConsumer LANGUAGES CXX)
|
||||
|
||||
find_package(Void CONFIG REQUIRED COMPONENTS Memory)
|
||||
|
||||
add_executable(void_memory_only_consumer main.cpp)
|
||||
target_link_libraries(void_memory_only_consumer PRIVATE Void::Memory)
|
||||
|
||||
enable_testing()
|
||||
add_test(NAME VoidMemoryOnlyConsumer COMMAND void_memory_only_consumer)
|
||||
@@ -0,0 +1,19 @@
|
||||
#include <Void/Memory/Arena.hpp>
|
||||
#include <Void/Memory/BlockPool.hpp>
|
||||
#include <Void/Memory/BudgetResource.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
Void::Memory::BudgetResource budget{1024 * 1024};
|
||||
Void::Memory::Arena arena{65536, 4096, budget};
|
||||
Void::Memory::BlockPool pool{64, 16, 16, 4096, 8, budget};
|
||||
|
||||
auto mem = arena.try_allocate(128, 32);
|
||||
auto blk = pool.try_allocate();
|
||||
if (!mem || !blk) {
|
||||
return 1;
|
||||
}
|
||||
pool.deallocate(*blk);
|
||||
(void)pool.trim_idle();
|
||||
return arena.reset().has_value() ? 0 : 1;
|
||||
}
|
||||
Reference in new issue
Block a user