From 1816851ac7acaf53a979c19bd8bc2d885f168f44 Mon Sep 17 00:00:00 2001 From: Lveyou <1339484752@qq.com> Date: Sat, 7 Feb 2026 17:45:12 +0800 Subject: [PATCH] =?UTF-8?q?*=20ArrayS=E5=86=85=E5=AD=98=E5=AF=B9=E9=BD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dl/base/dl_array_simd.h | 2 +- dl/math/dl_math.h | 14 ++++++++++---- dl/memory/dl_memory_pool.h | 13 ++++++------- project/dl_test/ui_sprite.cpp | 5 ++++- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/dl/base/dl_array_simd.h b/dl/base/dl_array_simd.h index c2f6e08e..adf9da61 100644 --- a/dl/base/dl_array_simd.h +++ b/dl/base/dl_array_simd.h @@ -51,7 +51,7 @@ namespace dl { template requires std::is_arithmetic_v -class ArrayS2 +class alignas(16) ArrayS2 { public: union diff --git a/dl/math/dl_math.h b/dl/math/dl_math.h index 17c508ee..c3a9a344 100644 --- a/dl/math/dl_math.h +++ b/dl/math/dl_math.h @@ -524,18 +524,24 @@ constexpr T Align(T x, T align) return ret; } +/** +* @brief 是否2的幂 +*/ +constexpr unsigned IsPow2(unsigned x) +{ + return x && !(x & (x - 1)); +} + /** * @brief 对齐align的倍数 * @param[in] align 必须是2的幂,否则返回0 */ constexpr unsigned AlignPow2(unsigned x, unsigned align) { - if ((0 == align) || (align & (align - 1))) - { + if (!IsPow2(align)) return 0; - } - return ((x + (align - 1)) & ~(align - 1)); + return (x + align - 1) & ~(align - 1); } /** diff --git a/dl/memory/dl_memory_pool.h b/dl/memory/dl_memory_pool.h index 5c7608f5..d08c2027 100644 --- a/dl/memory/dl_memory_pool.h +++ b/dl/memory/dl_memory_pool.h @@ -203,10 +203,10 @@ private: // Used列表的内存强行回收 for (auto& iter : _listUsed) - _aligned_free(iter); + free(iter);// _aligned_free(iter); for (auto& iter : _listFree) - _aligned_free(iter); + free(iter);// _aligned_free(iter); if (OUTPUT_DEBUG) { @@ -246,7 +246,7 @@ private: { LogStackTrack l{ OUTPUT_STACK }; log_test("转移 {}({}byte)内存,({})个", - typeid(T).name(), sizeof(GcRefInfo) + sizeof(T), count); + typeid(T).name(), GetNodeSize(), count); } } @@ -258,9 +258,8 @@ private: size_t num = _listUsed.size() + 10; for (size_t i = 0; i != num; ++i) { - unsigned MEM_SIZE = Math::AlignPow2(GetNodeSize(), 16); - log_info("{}", MEM_SIZE); - void* p = _aligned_malloc(16, MEM_SIZE); + unsigned MEM_SIZE = GetNodeSize();// Math::CeilToPow2(GetNodeSize()); + void* p = malloc(MEM_SIZE);// _aligned_malloc(MEM_SIZE, 16); if (p == nullptr) { @@ -273,7 +272,7 @@ private: { LogStackTrack l{ OUTPUT_STACK }; log_test("分配 {}({}byte)内存,({})个", - typeid(T).name(), sizeof(GcRefInfo) + sizeof(T), _listFree.size()); + typeid(T).name(), GetNodeSize(), _listFree.size()); } } diff --git a/project/dl_test/ui_sprite.cpp b/project/dl_test/ui_sprite.cpp index 258aed17..03faf896 100644 --- a/project/dl_test/ui_sprite.cpp +++ b/project/dl_test/ui_sprite.cpp @@ -454,8 +454,11 @@ void UISprite::_update_performance() createQuad(g_factory->GetSpriteTexSize(ball._spr)) + pos_next); } - ball._spr->Render(); + //ball._spr->Render(); } + gcText txt = g_factory->RenderText(); + txt->GetCoor()->SetPosition(toPosition(g_input->GetCursorPosition())); + txt->SetString(fmt::format("ball num: {}", _vecBall.size())); } void UISprite::_add_test()