How free () knows how much free memory?

Possible duplicate:
C-programming: how to find out how much for free?

In this fragment

void main() {
void *p = malloc(300);
printf("%d",sizeof(*p));
free(p);
}

How to freely know a lot of memory, is it supposed to be released from the void pointer?

I believe that if there is an internal table / function, it should be available to find out the sizes of any objects, while the output printfis1

+3
source share
4 answers

malloc and free do their own hidden accounting so that they can do the right thing.

, sizeof() , , sizeof() , malloc/free .

+3
+3

. , , , .. sizeof(void), .

+1

malloc , . free malloc , , .

Wiki

0

Source: https://habr.com/ru/post/1777962/


All Articles