Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于void* MemoryPoolAlloc(MemoryPool* mp, mem_size_t wantsize)部分的逻辑疑问 #14

Open
Zhichao-Yan opened this issue Apr 9, 2024 · 1 comment
Labels
wontfix This will not be worked on

Comments

@Zhichao-Yan
Copy link

  1. 请问:mp->mempool_size代表的什么意思?是默认的一个标准内存池大小吗?
  2. 剩余可新增内存池大小不是应该等于mp->max_mempool_size - mp->alloc_mempool_size吗?
    if (mp->auto_extend) {
        // 超过总内存限制
        if (mp->alloc_mempool_size + total_needed_size > mp->max_mempool_size) {
            goto err_out;
        }
        // 问题1: 
        mem_size_t add_mem_sz = mp->max_mempool_size - mp->mempool_size;
        // 如果空间足够则按 mempool_size 新增, 不足则分配剩下所有内存
        add_mem_sz = add_mem_sz >= mp->mempool_size ? mp->mempool_size
                                                     : add_mem_sz;
        if (!extend_memory_list(mp, add_mem_sz)) goto err_out;
        // 更新实际分配内存
        mp->alloc_mempool_size += add_mem_sz;

        goto FIND_FREE_CHUNK;
    }
@userpro
Copy link
Owner

userpro commented Oct 12, 2024

问题1:是的
问题2:这里实现的很粗糙,内存块的增长只能以mp->mempool_size的整数倍进行,而且只是新增一个块,而不是原地增加,所以剩余可新增内存池大小是这样计算的;
补充:根据前面的判断total_needed_size只能是小于mp->mempool_size的,所以这里就看是可以新增一个mp->mempool_size大小,还是剩下点边角料一起全加了

@userpro userpro added the wontfix This will not be worked on label Oct 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants