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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With