by smcameron · 2y ago · 0 comments
It may compile, but it might not link. With very large static arrays, in the link step, you might get something like this:
my_program.o: In function `my_function':
my_program.c:(.text+0xf38): relocation truncated to fit: R_X86_64_PC32 against `.bss'
It's due to the linker assuming statically allocated things can be addressed with a 4-byte pointer (I encountered this on x86_64 arch). Using malloc to allocate the array will fix this.That being said, using malloc once to allocate a very large array will get the same dynamic allocation of backing RAM as described in the article on linux, assuming overcommit is enabled.
I don't know what Windows does.
Windows does not allow overcommit. The commit limit is the total size of RAM + the size of the page file, attempting to commit more than that will fail.