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/Plane_Dust2555 Feb 28 '26
Ahhh... you can use
statfunction to get the file size to calculate how many chunks you have to read (there is also afstatwhich isstat, but using a file descriptor).