Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fread number of bytes limit

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?

like image 586
user2320928 Avatar asked Feb 16 '23 06:02

user2320928


1 Answers

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.

like image 146
Zac Howland Avatar answered Feb 22 '23 21:02

Zac Howland