首页 > 解决方案 > Function to get the Size of allocated Memory from pointer only

问题描述

How is it possible to get the size of memory allocated knowing only the pointer name returned by malloc function ? I suppose it is possible because free function as only this pointer as parameter but I do not know how to do that.

size_t myfoo (void *ptr) {
/* some instruction to get the size : This is the question*/ }

main () {
int * ptr;
ptr=malloc(100);
printf("%ud \n",myfoo(ptr)); }

标签: c

解决方案


推荐阅读