I have C++ application that allocate huge buffer of memory - 1 GB minimum, but often 2 or 4 GB, sometimes even more.
I allocate using operator new, which is practically the same as malloc (this is why I added tag C)
Lately I am thinking to do some change - I can create a huge file and mmap it, instead of using allocation. Varnish suppose to do something like that.
This will help if computer have no memory, program will work on the disk, else it will work as if I did allocated with operator new or malloc.
However I am not sure what mmap options I should choose - map no need to be shared, also no need to be synchronized to the disk, unless this is necessary (e.g. no memory).
I know about madvise - access will be random.
I want to be portable between Linux and MacOS, but Linux only solution is ok too.
As a bonus, I want to be able to synchronize the mmap memory to the file, but only when I decide.