That's implementation specific, the only thing defined is how it should look like it works to the application, and the implementation is free to use whatever structure it needs to give good performance/low memory use/...
As an example, one way would be to reserve a few bytes before the block returned, and store the size there. For example, if you malloc()
25 bytes, it would actually reserve 29 bytes, store the size in the 4 first bytes and return a pointer to the last 25 bytes. free()
can then take the pointer, subtract 4 and read the size.
Another way would be to store the address/size in a hash table, so that when someone calls free()
, it can look the size up in the hash table.