FThompson
FThompson

Reputation: 28687

Read from anonymous / non-persisted memory-mapped file in Java

Java supports memory-mapped files through a MappedByteBuffer retrieved via FileChannel#map. These files allow multiple processes to share memory, among other uses.

As noted in the Wikipedia article, there are two types of memory-mapped files:

Persisted

Persisted files are associated with a source file on a disk. The data is saved to the source file on the disk once the last process is finished. These memory-mapped files are suitable for working with extremely large source files.

Non-persisted

Non-persisted files are not associated with a file on a disk. When the last process has finished working with the file, the data is lost. These files are suitable for creating shared memory for inter-process communications (IPC).

Persisted memory-mapped files are easily acquirable via FileChannel#map. Non-persisted (anonymous) files, however, cannot be acquired in this manner. In Python, for example, with mmap, one can pass -1 as the file number and unique tag names (in Windows) to acquire segments of an anonymous memory-mapped file.

  1. Is it possible to read from an anonymous / non-persisted memory-mapped file in Java?

  2. If so, is it possible (in Windows) to specify tag names to map anonymous file data?

Upvotes: 1

Views: 942

Answers (0)

Related Questions