free()如何工作 [英] how free() works

查看:111
本文介绍了free()如何工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们只是将指向动态分配变量的指针传递给free()

函数。

如何决定要释放的字节数?

We merely pass the pointer to dynamically allocated variable to free()
function.
How does it decide about the number of bytes to be freed?

推荐答案

2007年12月25日星期二22:16:22 -0800(太平洋标准时间),riva< ra ********* @ gmail .com>

写道:
On Tue, 25 Dec 2007 22:16:22 -0800 (PST), riva <ra*********@gmail.com>
wrote:

>我们只是将指向动态分配变量的指针传递给free()
函数。
如何决定要释放的字节数?
>We merely pass the pointer to dynamically allocated variable to free()
function.
How does it decide about the number of bytes to be freed?



它取决于实现。通常,使用malloc分配的块大小至少是sizeof(size_t)字节,大于

请求。这些额外的字节用于存储块的大小,

并且它们在返回指针之前''。但请记住,每个编译器都可以自由地按照自己喜欢的方式进行操作。所以这不是经验法则。


祝你好运,


Zara


It is implementation dependent. Usually, the chunk of bytes realy
assigned with malloc is at least sizeof(size_t) bytes larger then the
request. These extra bytes are used to store the size of the chunk,
and they are ''before'' the pointer returned. But please remember thet
each compiler is free to do as it likes, so thi is no rule of thumb.

Best regards,

Zara


伙计们......我想做以下事情!


我要编辑一个文本文件通过我的C程序。


文本文件如下

1

2

3

4

i想要改变内容


1

2

100

3

4


提前致谢..
Guys..i want to do the following!

I want to edit a text file through my C program.

The text file is as follows
1
2
3
4

i want to change the contents to

1
2
100
3
4

Thanks in advance..


riva写道:
riva wrote:

我们只是将指向动态分配变量的指针传递给free()

函数。

如何决定要释放的字节数?
We merely pass the pointer to dynamically allocated variable to free()
function.
How does it decide about the number of bytes to be freed?



`malloc`和`free`是朋友,没有秘密来自一个

另一个。


不同的实现,如不同的朋友,有不同的b / b
秘密。


-

阴谋刺猬

含义在定义之前。

`malloc` and `free` are friends and have no secrets from one
another.

Different implementations, like different friends, have different
secrets.

--
Conspiracy Hedgehog
Meaning precedes definition.


这篇关于free()如何工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆