Search code examples
javamemory-managementioreal-timenio

Why would someone use a Memory Mapped File in PRIVATE mode?


The documentation does not say much besides:

Private: Changes made to the resulting buffer will not be propagated to the file and will not be visible to other programs that have mapped the same file; instead, they will cause private copies of the modified portions of the buffer to be created. (MapMode.PRIVATE)

In what situation is it desirable and what advantages does it have?


Solution

  • If you're running a genetic-algorithm experiment on a large dataset, you might wish to start eight or more clients -- one per core, two per core, etc. -- to work with the same starting data, make modifications to the data as it performs the computation, and then save only "final results" of the starting seed for the random number generator and the "score" against which the algorithm is being measured.

    The intermediate results might not have any value and you wouldn't want any of the clients to ever see intermediate results from other clients nor taint the initial seed data.