Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#1598·gperftools

Adding custom metadata at end of object

Author: SaiVKCreated Jun 15, 2025Updated Jun 23, 2025

Hello everyone I am trying to add some custom metadata, 8 bytes, for each object. For that,

  1. I modified the tc_malloc(), to add 8 bytes to the size
  2. Retrieve the pointer returned by malloc_fast_path(). I tried adding the metadata to the base of the allocation, but figured out the tcmalloc itself stores free list pointers. So stored the metadata at the end of the allocation.
  3. Returned the pointer.

Is this a correct way to implement? Will it break any tcmalloc internals? I am using this metadata to perform some analysis on the benchmark, so not worries about performance or so.

Also, another query, I use the LD_PRELOAD mechanism to load tcmalloc. So, is it the case that all mallocs are re-routed to tc_malloc()? Or is there some other function in addition to it?

Thanks

Source: gperftools/gperftools

View original on GitHubView discussion on GitHub