Lastly here, it will check if it actually inserted a chunk into the tcache that will serve as a reallocation for the requested size, it will allocate it from the tcache.
This part of the code is shown:
++tcache_unsorted_count;
if (return_cached
&& mp_.tcache_unsorted_limit > 0
&& tcache_unsorted_count > mp_.tcache_unsorted_limit)
{
return tcache_get (tc_idx);
}
That if statement only passes if mp_.tcache_unsorted_limit > 0, by default, mp_.tcache_unsorted_limit is equal to zero: https://elixir.bootlin.com/glibc/glibc-2.39/source/malloc/malloc.c#L1928
The actual check and allocation of a tcache chunks happens after the loop is finished: https://elixir.bootlin.com/glibc/glibc-2.39/source/malloc/malloc.c#L4246
This part of the code is shown:
++tcache_unsorted_count; if (return_cached && mp_.tcache_unsorted_limit > 0 && tcache_unsorted_count > mp_.tcache_unsorted_limit) { return tcache_get (tc_idx); }That if statement only passes if
mp_.tcache_unsorted_limit > 0, by default,mp_.tcache_unsorted_limitis equal to zero: https://elixir.bootlin.com/glibc/glibc-2.39/source/malloc/malloc.c#L1928The actual check and allocation of a tcache chunks happens after the loop is finished: https://elixir.bootlin.com/glibc/glibc-2.39/source/malloc/malloc.c#L4246