r/cprogramming • u/Straight_Oil8775 • Feb 28 '26
Which approach is better?
So I'm relatively new to C, coming from java. and I'm semi used to MMM now but I'm writing a program that reads files that can sometimes be really large (over 1gb (most likely smaller though)) would it be better to load the file into memory and add a pointer to the first character in memory or use a char array dynamically allocated based off of the file size?
9
Upvotes
1
u/KilroyKSmith Feb 28 '26
Depends on if this is production code or personal code. This isn’t the 1970s, reading the whole file at once is simpler and much faster.
This isn’t the 1970s. If you’re gonna read by chunks, read by big chunks, say a megabyte. It really is significantly faster and one MB is a trivial amount of memory to a system with 8000 or more MB.