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?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- Why are memory addresses incremented by 4 in MIPS?
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
In practice,
fread()
will have no problem slurping in a 50MB file. That's not really a “large file” by modern standards.fread()
returns the number of items read, and is guaranteed to return a short item count only on end-of-file (if you asked for more items than are in the file) or error. You must check that the returned item count is what you expect and, if it is short, usefeof()
andferror()
to distinguish between EOF and error.Theoretically, yes, it can read any number of bytes up to the maximum of
size_t
(which is anunsigned 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.