读取字节数限制 [英] Fread number of bytes limit

查看:89
本文介绍了读取字节数限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

fread是否对它一次可以读取的字节数有限制? 还是我可以读取要装入指针的任何尺寸? 例如,我可以使用fread将50MB的文件读入char指针一次吗?

Does fread have a limit for the number of bytes it can read at once? Or I can read any size I would like to charge in to my pointer? For example, Can I read file of 50MB once using fread to charge it into char pointer?

推荐答案

从理论上讲,是的,它可以读取任意数量的字节,最大不超过size_t(这是一个unsigned int(在32-位系统).但是,由于必须将缓冲区分配在连续的块中,因此一次读取一个大文件(对于较大的文件,您可能无法读取)是不可行的,也不是明智的.创建一个足以容纳文件的内存缓冲区.)通常,您将有一个较小的缓冲区并循环遍历文件,将其分块加载到内存中.

Theoretically, yes, it can read any number of bytes up to the maximum of size_t (which is an unsigned int (roughly 4GB on a 32-bit system). However, since your buffer will have to be allocated in a contiguous block, it is not likely to be feasible, nor advisable, to read in a large file at once (and for substantially large files, you will probably fail to create a memory buffer large enough to hold the file). Typically, you will have a smaller buffer and loop over the file loading it into memory in chunks.

这篇关于读取字节数限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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