a question about "free"

int* i = malloc(4*sizeof(int));
free(i)

problem:
how free function know to free 4*sizeof(int) bytes?

That depends on the implementation, but usually the memory management will store the allocated size somewhere (for example, directly before the returned address).
Last edited on
Topic archived. No new replies allowed.