I was learning about dynamic memory allocation functions and in that whenever we use malloc function you would have specified some bytes to allocate in the memory.
So when we assign the address of this allocated memory block the pointer will only have the information about the address of the first bite
When we call the free function on this pointer again
free()
how does it know how many bytes to deallocate since it takes only the pointer as the argument which only contains information about this first bite of the allocated memory.
Does the operating system keep some kind of a database table to hold the information about the address of the first byte allocated and the number of bytes are allocated?
Or does something else happen entirely?
If something like this database exists then who is maintaining this database and the how I can access this externally or explicitly in my program?
Use cases for accessing this info :- For anyone who is saying we don't need this info....
Let's say I am within a function and I haven't passed a parameter about how many integers my array has... In this case, to minimise the number of arguments, we can do this hack (although it's not desirable,)