I need to set some default value for all entires in a very large array.
It takes me quite long time (110-120 ms) and i suspect it happens because of misses in memory.
I use memset/std:fill to set the default value. Is there a way to make sure that the array will reside in memory before the memset/fill?
Assuming this is a large memory-mapped file, you can use the madvise() libc call with the
MADV_WILLNEEDargument to hint to the OS that you’ll be wanting to access the region mentioned soon.However YMMV, as the array needs to be large enough that the benefit of the resulting syscall isn’t outweighed by the cost of making the call.