本文介绍了malloc分配内存给指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我按以下方式为结构指针分配内存
Hi,
I allocate memory for struct pointer as following manner
*p=(node*)malloc(2000);
我只使用很少的内存.我想找到未使用的内存形式,然后重复使用.
如果使用free(p)
,它将释放所有分配的内存,但是我只需要释放未使用的内存.
您能帮我吗?
I use little amount of memory only. I want to find unused memory form that and I want to reuse that.
if I use the free(p)
, it would free up all the allocated memory, but I need to free only the unused memory.
Can you help me?
推荐答案
*p=(node*)malloc(sizeof(node));
将分配node
对象所需的确切内存量.
will allocate the exact amount of memory required for a node
object.
这篇关于malloc分配内存给指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!