本文介绍了一些POSIX的功能为什么得到一个单元号和单元尺寸参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请参阅:

malloc函数只是得到一个数组的大小来分配。

The malloc function simply gets a array size to allocate.

但是:

和:

只是2的接收单元的单元尺寸和数量函数的例子。

Are just 2 examples of functions that receive element size and number of elements.

为什么这么差?难道不是更简单地得到一个尺寸,这就是它?

Why's that difference? Doesn't it more simple to get a size and that's it?

推荐答案

这是一个多原因的说明,但值尺寸 nmemb个确有差别尽可能的返回值 FREAD(3)的fwrite(3)关注。它们返回读取或写入的元素,其中每个元素的大小由大小参数确定的数量。

This is more of a note than a reason, but the values of size and nmemb do make a difference as far as the return value of fread(3) and fwrite(3) is concerned. They return the number of elements read or written, where the size of each element is determined by the size parameter.

POSIX还表示,下面再。 回答和评论有一些有趣的讨论重新。 释放calloc()

Update: This answer and the comments has some interesting discussion re. calloc().

这篇关于一些POSIX的功能为什么得到一个单元号和单元尺寸参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 00:53