Open vkensou opened 1 month ago
Bot detected the issue body's language is not English, translate it automatically.
Title: Memory allocation error
Calling tb_align_malloc(2104, 512);
will cause an assertion error:
Allocate memory normally
[tbox]: [allocator]: [assert]: at tb_assert_impl(): 300, C:\Users\user\AppData\Local\.xmake\cache\packages\2410\t\tbox\v1.7.6\source\tbox \src\tbox\prefix\assert.h: expr[!((tb_size_t)data & (align - 1))] at tb_allocator_align_malloc_(): 373, src\tbox\memory\allocator.c
windows msvc but I feel it has little to do with the system and compiler
xmake.lua
add_requires("tbox v1.7.6", {configs = {debug = is_mode("debug")}})
target("main")
set_kind("binary")
add_packages("tbox")
add_files("main.cpp")
main.cpp
#include "tbox/tbox.h"
int main()
{
tb_init(tb_null, tb_null);
tb_align_malloc(2104, 512);
}
看了代码
tb_pointer_t tb_allocator_align_malloc_(tb_allocator_ref_t allocator, tb_size_t size, tb_size_t align __tb_debug_decl__)
{
// ...
tb_byte_t diff = (tb_byte_t)((~(tb_long_t)data) & (align - 1)) + 1;
// ...
}
是因为这句,计算diff的时候转到u8了,对齐到512的话超出范围了
搞这么大对齐干嘛。。
Bot detected the issue body's language is not English, translate it automatically.
Why do we have such a big alignment? .
搞这么大对齐干嘛。。
我想用tbox作为c++的memory_resource的上游,然后vector resize几次以后就这样的。。。
描述问题
调用
tb_align_malloc(2104, 512);
会有断言错误:期待的结果
正常分配内存
错误信息
相关环境
windows msvc 但我感觉跟系统和编译器关系不大
xmake.lua
main.cpp