This is my Java blog with various tips and tricks that are targeted for medium and advanced Java users.   I work as a Java Core Library Developer at O

Minborg's Java Pot: Java 20: Colossal Sparse Memory Segments

submited by
Style Pass
2023-01-24 23:00:15

This is my Java blog with various tips and tricks that are targeted for medium and advanced Java users. I work as a Java Core Library Developer at Oracle. The views on this blog are my own and are not necessarily the ones of Oracle, Inc. Happy Reading! /Per Minborg

Did you know you can allocate memory segments that are larger than the physical size of your machine’s RAM and indeed larger than the size of your entire file system? Read this article and learn how to make use of mapped memory segments that may or may not be “sparse” and how to allocate 64 terabytes of sparse data on a laptop.

Mapped memory is virtual memory that has been assigned a one-to-one mapping to a portion of a file. The term “file” is quite broad here and may be represented by a regular file, a device, shared memory or any other thing that the operating system may refer to via a file descriptor.

Accessing files via mapped memory is often much faster than accessing a file via the standard file operations like read and write . Because mapped memory is operated on directly, some interesting solutions can also be constructed via atomic memory operations such as compare-and-set operations, allowing very efficient inter-thread and inter-process communication channels. 

Leave a Comment