size_t or long for the size of a string containing a file? size_t or long for the size of a string containing a file? unix unix

size_t or long for the size of a string containing a file?


I think you want to use mmap() instead.


I think the issue of casting is moot. Since the smaller of the two, long, has a maximum of +2^31 (if signed), if you read all of that at once you'd be occupying 2GB of memory. This is usually a bad idea.


If your files are large enough for this to be an issue, they are also large enough for the memory allocation to almost certainly fail.

Either don't worry about it, or switch to an OS specific memory mapping technique.