Memory Mapped file segment (file is empty)

Johannes Lichtenberger lichtenberger.johannes at gmail.com
Wed Jun 24 22:48:41 UTC 2020


Hi,

I guess that's not the right mailinglist to ask for help with the API, but
maybe you can point me at least somewhere.

Currently I face the problem, that I can't get a memory segment on an empty
file when I want to memory map a file. However, a writer would write to the
memory mapped file.

I want to be able to swap a rather old RandomAccessFile based
implementation with a memory mapped file implementation. The two classes
(actually three, but only the FileReader and FileWriter matters) are rather
simple.

The old package:

https://github.com/sirixdb/sirix/tree/master/bundles/sirix-core/src/main/java/org/sirix/io/file


and the new package

https://github.com/sirixdb/sirix/tree/master/bundles/sirix-core/src/main/java/org/sirix/io/memorymapped

This line fails if the underlying file size is 0:

https://github.com/sirixdb/sirix/blob/7bdbd5d17a034f02902f8f7dd0ef7012d89c81fb/bundles/sirix-core/src/main/java/org/sirix/io/memorymapped/MemoryMappedFileWriter.java#L83

Stacktrace  (Precondition fails, so I'm not using the API in the intended
way):

java.lang.IllegalArgumentException: Requested bytes size must be > 0.

at
jdk.incubator.foreign/jdk.internal.foreign.Utils.makeMappedSegment(Utils.java:140)
at
jdk.incubator.foreign/jdk.incubator.foreign.MemorySegment.mapFromPath(MemorySegment.java:398)
at
org.sirix.io.memorymapped.MemoryMappedFileWriter.<init>(MemoryMappedFileWriter.java:83)


So, it might be easiest to write a more or less direct conversion to the
Foreign Memory API. Maybe someone can help or point me to a helpful
Mailinglist/Forum/whatever.

Kind regards
Johannes


More information about the panama-dev mailing list