From f69f6e297a34678de0e1f209d196dd7bef2a4273 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Wed, 18 Feb 2026 12:57:07 +0100 Subject: Added basic memory usage estimation --- lib/core/c++/common.hpp | 1 + lib/core/c++/memory.hpp | 20 ++++++++++++++++++++ lib/core/tests/memory.cpp | 42 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 62 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/core/c++/common.hpp b/lib/core/c++/common.hpp index 5f7129f..280d953 100644 --- a/lib/core/c++/common.hpp +++ b/lib/core/c++/common.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include namespace kel { namespace lbm { diff --git a/lib/core/c++/memory.hpp b/lib/core/c++/memory.hpp index b6a089e..e97c7fc 100644 --- a/lib/core/c++/memory.hpp +++ b/lib/core/c++/memory.hpp @@ -21,11 +21,31 @@ struct memory_size_helper> { static constexpr uint64_t bytes = saw::ct_multiply::value * memory_size_helper::bytes; }; +template +struct memory_size_helper> { + static constexpr uint64_t bytes = saw::ct_multiply::value * memory_size_helper::bytes; +}; + template struct memory_size_helper> { static constexpr uint64_t bytes = memory_size_helper::InnerSchema>::bytes; }; +template +struct memory_size_helper> { + + template + static constexpr uint64_t apply_i() { + if constexpr ( i < sizeof...(Members) ){ + using M_I = typename saw::parameter_pack_type::type; + return apply_i() + memory_size_helper::bytes; + } + return 0u; + } + + static constexpr uint64_t bytes = apply_i<0u>(); +}; + template class memory_estimate_helper final { private: diff --git a/lib/core/tests/memory.cpp b/lib/core/tests/memory.cpp index 27cd938..cdc6f8c 100644 --- a/lib/core/tests/memory.cpp +++ b/lib/core/tests/memory.cpp @@ -5,14 +5,54 @@ namespace { namespace sch { using namespace saw::schema; + +using TStruct = Struct< + Member, + Member, + Member +>; + +using TChunk = kel::lbm::sch::Chunk; +using TBChunk = kel::lbm::sch::Chunk; + +using TChunkStruct = Struct< + Member, + Member +>; } SAW_TEST("Memory Estimate"){ using namespace kel::lbm; - SAW_EXPECT((memory_estimate().get() == 4u), std::string{"Float32 isn't 4 bytes, but "} + std::to_string(memory_estimate().get()) ); + SAW_EXPECT((memory_estimate().get() == 4u), "Float32 isn't 4 bytes" ); SAW_EXPECT((memory_estimate>().get() == 60u), "FixedArray isn't 60 bytes"); SAW_EXPECT((memory_estimate, sch::UInt8>().get() == 61u), "FixedArray + UInt8 isn't 61 bytes"); } +SAW_TEST("Memory Estimate Struct"){ + using namespace kel::lbm; + + SAW_EXPECT((memory_estimate().get() == 13u), "TStruct isn't 13 bytes" ); + // SAW_EXPECT((memory_estimate().get() == 13u), "TStruct isn't 13 bytes" ); +} + +SAW_TEST("Memory Estimate Scalar"){ + using namespace kel::lbm; + + SAW_EXPECT((memory_estimate>().get() == 1u), "Scalar of UInt8 isn't 1 bytes" ); + // SAW_EXPECT((memory_estimate().get() == 13u), "TStruct isn't 13 bytes" ); +} + +SAW_TEST("Memory Estimate Chunk"){ + using namespace kel::lbm; + + SAW_EXPECT((memory_estimate().get() == 480u), std::string{"TChunk isn't 480 bytes "} + std::to_string(memory_estimate().get()) ); +} + +SAW_TEST("Memory Estimate Struct of Chunk"){ + using namespace kel::lbm; + + SAW_EXPECT((memory_estimate().get() == 960u), std::string{"TChunk isn't 480 bytes "} + std::to_string(memory_estimate().get()) ); +} + } -- cgit v1.2.3