为什么释放calloc的目的不是分配任意值? [英] Why calloc wasn't intended to assign arbitrary values?

查看:213
本文介绍了为什么释放calloc的目的不是分配任意值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据原因的malloc + memset的慢释放calloc?

的malloc + memset的释放calloc 慢下一定的条件。

malloc+memset is slower than calloc under certain conditions.

为什么没有释放calloc 写的这样一种方式,它可以采取额外的参数(如 memset的),以覆盖由零缺省分配?如果它做了什么本来的那个效果?

Why wasn't calloc written in such a way that it can take an extra value argument ( like memset) to override default assignment by zero? What would have been the effect of that if it were done?

推荐答案

这些释放calloc memset的初始化操作上一个字节的水平,所以即使 memset的 0 不同的值是不是有用。至少我不记得有它不同的值使用。晴你比字符更广泛的基本类型分配内存。

These calloc or memset initializations operate on a byte level, so even memset with a value different from 0 is not that usefull. At least I don't remember having it used with different values. Mostly you allocate memory for a base type that is wider than char.

另一个方面是,释放calloc 是初始化和未分配。平台可能有到 0 提供的所有字节的快速初始化内建命令,传递参数初始化时,你会不会抓住这个。

The other aspect is that calloc is initialization and not assignment. Platforms may have builtins that provide a fast initialization of all bytes to 0, you wouldn't capture this when passing an argument to initialize.

但是可能是最重要的方面是,这是C的历史这些接口从一开始就发起,并且不可能改变

But probably the most important aspect is that this is history of C. These interfaces originate from the very beginning and are impossible to change.

这篇关于为什么释放calloc的目的不是分配任意值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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