I have a pointer. I know its address (I got as an argument to a function), and I know that it points to a memory address previously allocated by the malloc()
call.
Is there any way to know the size of this allocated memory block?
I would prefer a cross-platform, standard solution, but I think these do not exist. Thus, anything is okay, even hardcore low-level malloc data structure manipulation, if there is no better. I use glibc with x86_64 architecture and there is no plan to run the result elsewhere. I am not looking for a generic answer, it can be specific to glibc/x86_64.
I think, this information should be available, otherways realloc()
could not work.
This question asks for a generic, standard-compliant solution, which is impossible. I am looking for a glibc/x86_64 solution which is possible, because the glibc is open source and the glibc realloc()
needs this to work, and this question allows answers by digging in non-standard ways in the low-levels malloc internals.