Skip to content
New issue

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

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

Already on GitHub? # to your account

Problem about SGI-STL V3.3/stl_alloc.h __default_alloc_template::_S_chunk_alloc #5

Open
kagtag opened this issue Feb 29, 2020 · 1 comment

Comments

@kagtag
Copy link

kagtag commented Feb 29, 2020

if (__bytes_left > 0) {
_Obj* __STL_VOLATILE* __my_free_list =
_S_free_list + _S_freelist_index(__bytes_left);
((_Obj*)_S_start_free) -> _M_free_list_link = *__my_free_list;
*__my_free_list = (_Obj*)_S_start_free;
}

I think this logic is only correct when __bytes_left is a multiple of 8,
otherwise, __bytes_left would be less than the chunk size of the computed slot.
For example, if __bytes_left is 5, the computed slot is 0, with chunk size of 8, if caller function requests 7 bytes of memory, normally allocator returns 8 bytes of memory, but this chunk has only 5, which would be not enough.

@ghost
Copy link

ghost commented May 10, 2020

You can check the malloc logic. When you malloc size of N , the N has adjust to multiple of 8 before malloc.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant