简体   繁体   English

使用读取分配缓冲区 (C)

[英]Buffer allocating with read (C)

I wonder if read function does allocate the Buffer size to the Buffer that passes to it or not?我想知道 read function 是否将缓冲区大小分配给传递给它的缓冲区? I need to know that in order to see if I need to free the Buffer or not after I am done with it.我需要知道这一点,以便查看完成后是否需要释放缓冲区。

Here is the prototype of the function read:下面是 function 的原型:

ssize_t read(int fildes, void *buf, size_t nbytes);

No, read does not do any allocation.不,读取不做任何分配。 It reads data into the buffer you provide as an argument, which must have been allocated by you prior to calling read.它将数据读取到您作为参数提供的缓冲区中,该缓冲区必须在调用 read 之前由您分配。 You can use a buffer on the heap or stack, or a global buffer;您可以在堆或堆栈上使用缓冲区,也可以使用全局缓冲区; its your choice.这是你的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM