* ArrayS内存对齐

This commit is contained in:
lveyou committed 2026-02-07 17:45:12 +08:00
1 parent 27f71b2b8e
commit 1816851ac7
4 files changed
+21 -13

No files matched your search

+1 -1
View File
@@ -51,7 +51,7 @@ namespace dl
{
template<typename T, size_t N>
requires std::is_arithmetic_v<T>
class ArrayS2
class alignas(16) ArrayS2
{
public:
union
+10 -4
View File
@@ -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);
}
/**
+6 -7
View File
@@ -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());
}
}
+4 -1
View File
@@ -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()