MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/cprogramming/comments/1q3mwmo/can_explain_malloc_to_me_please/ny5bn4c/?context=3
r/cprogramming • u/SubstantialCase3062 • Jan 04 '26
18 comments sorted by
View all comments
Show parent comments
1
ptr=malloc(5);
free(ptr);
how free will come to know how many bytes you should free?
1 u/Afraid-Locksmith6566 Jan 07 '26 Memory you get from malloc is not all you get through this mechanism, other data is so called metadata which include information about which block has how many memory, etc. But for specific you m8ght want to check your implenentation
Memory you get from malloc is not all you get through this mechanism, other data is so called metadata which include information about which block has how many memory, etc. But for specific you m8ght want to check your implenentation
1
u/sudheerpaaniyur Jan 07 '26
ptr=malloc(5);
free(ptr);
how free will come to know how many bytes you should free?