uTools-Manuals/docs/c/free.html

48 lines
1.2 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<h1>动态内存 - free</h1>
<p>原型extern void free(void *p);</p>
<p>用法:#include &lt;alloc.h></p>
<p>功能释放指针p所指向的的内存空间。</p>
<p>说明p所指向的内存空间必须是用calloc,malloc,realloc所分配的内存。
如果p为NULL或指向不存在的内存块则不做任何操作。</p>
举例:<pre><code class="language-c">
// free.c
#include &lt;syslib.h>
#include &lt;alloc.h>
main()
{
char *p;
clrscr(); // clear screen
textmode(0x00);
p=(char *)malloc(100);
if(p)
printf("Memory Allocated at: %x",p);
else
printf("Not Enough Memory!\n");
getchar();
free(p); // release memory to reuse it
p=(char *)calloc(100,1);
if(p)
printf("Memory Reallocated at: %x",p);
else
printf("Not Enough Memory!\n");
free(p); // release memory at program end
getchar();
return 0;
}
</code></pre>相关函数:<a href="calloc.html">calloc</a>,<a href="malloc.html">malloc</a>,<a href="realloc.html">realloc</a>