0

I remember seeing a runtime diagnostics of a program that would output top memory users in something like:

PC          Memory Allocated      Times
----------  ----------------      -----
0xd94eded0           3270656       1234
0xede33294           2313324        204
0xc343340c             23820        102
...

I know the program is written in C. The PC is the address of code which allocates memory.

I suppose someone can build a hash table to keep track of all the callers of malloc() using __builtin_return_address(). But when memory is released, free() does not tell the size of memory being freed. How could the program figure that one out?

some user
  • 876
  • 1
  • 12
  • 26
  • Did you check if valgrind can provide the info you want? (I'm not saying it can. But it might.) – ikegami Apr 03 '23 at 03:57
  • *"How could the program figure that one out?"* If the logging `malloc` keeps a list of all allocations, a logging `free` could consult that list. – BoP Apr 03 '23 at 10:31
  • Does this answer your question? [GLIBC malloc implementation bookkeeping](https://stackoverflow.com/questions/62095835/glibc-malloc-implementation-bookkeeping) – Zwy Apr 03 '23 at 11:30

0 Answers0