Questions tagged [mappedbytebuffer]

A direct byte buffer whose content is a memory-mapped region of a file.

A direct byte buffer whose content is a memory-mapped region of a file.

Part of java.nio package from version 1.4

Docs: https://docs.oracle.com/javase/7/docs/api/java/nio/MappedByteBuffer.html

61 questions
2
votes
1 answer

How to read line by line from mapped file in java using MappedByteBuffer

I want to read a large file in a very fast way. I am using MappedByteBuffer like this: String line = ""; try (RandomAccessFile file2 = new RandomAccessFile(new File(filename), "r")) { FileChannel fileChannel =…
bcsta
  • 1,963
  • 3
  • 22
  • 61
2
votes
3 answers

Java 8 Application using all of System RAM and then crashing with a SIGBUS. Whats going on here?

I have a Java 8 Application that takes in messages over the network and writes to multiple Memory Mapped files using Java NIO MappedByteBuffer. I have a reader that reads messages simultaneously from these files in order and deletes read files again…
2
votes
0 answers

Writing and Reading a MappedByteBuffer in Java

I'm learning about Memory Mapped files in java. I would like to know how to write/read to a MappedByteBuffer. Here's the code I'm using for writing to MappedByteBuffer. private static void write(String strFilePath) { File fl = new…
1
vote
2 answers

How to read a File character-by-character in reverse without running out-of-memory?

The Story I've been having a problem lately... I have to read a file in reverse character by character without running out of memory. I can't read it line-by-line and reverse it with StringBuilder because it's a one-line file that takes up to a…
JumperBot_
  • 551
  • 1
  • 6
  • 19
1
vote
1 answer

How to prevent MappedByteBuffer put from writing null characters at the end of file?

I am using Java's MappedByteBuffer with a fixed buffer size to write into a file, as part of an assignment. It should write character by character since the buffer size can be smaller than the line length. But the problem is that it writes the…
Fabrício
  • 91
  • 2
  • 7
1
vote
0 answers

How to read large files with MappedByteBuffer?

I want to read a 30GB file using MappedByteBuffer. try (FileChannel sourceChannel = new RandomAccessFile("sample.csv", "r").getChannel()) { MappedByteBuffer buf = sourceChannel.map(FileChannel.MapMode.READ_ONLY, 0,…
membersound
  • 81,582
  • 193
  • 585
  • 1,120
1
vote
1 answer

Cannot read file in chunks with MappedByteBuffer

During read ops i get java.io.IOException: Channel not open for writing - cannot extend file to required size I have written simple program that reads file with MappedByteBuffer. The idea is to read file with regions according to API. But during…
jspens
  • 11
  • 1
1
vote
2 answers

Java Mapped Byte Buffer - garbage values in buffer

I'm experimenting with Mapped Byte Buffer (Java), I have to use DirectBuffer on a file to perform some arithmetic operations: MappedByteBuffer mbf = new RandomAccessFile("blah.bin",…
humblecoder
  • 499
  • 2
  • 5
  • 15
1
vote
0 answers

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…
FThompson
  • 28,352
  • 13
  • 60
  • 93
1
vote
2 answers

Is there a way to memory-map files in Java that are larger than Integer.MAX_VALUE?

FileChannel#map, which is used to map a file (i.e., initiate a memory map), takes a long as length parameter. Yet, the documentation on FileChannel#map says the following: size - The size of the region to be mapped; must be non-negative and no…
1
vote
3 answers

Java, why reading from MappedByteBuffer is slower than reading from BufferedReader

I tried to read lines from a file which maybe large. To make a better performance, I tried to use mapped file. But when I compare the performance, I find that the mapped file way is even a a little slower than I read from BufferedReader public long…
JaskeyLam
  • 15,405
  • 21
  • 114
  • 149
1
vote
1 answer

Java-Does mappedbytebuffer occupy direct memory?

I am curious whether the mappedbytebuffer occupies direct memory in Java? As mentiond in here A direct byte buffer may also be created by mapping a region of a file directly into memory When I map a file into memory, the direct memory should be…
Jenson
  • 87
  • 5
1
vote
0 answers

Does memory mapping files interfere with memory management?

I wrote an app that uses a memory mapping to access file. Read speed increased dramatically, so it was a success. As expected, the memory allocated for the ByteBuffer is not counted against the VM heap. In a heap dump, it appears that my app uses…
Kevin Krumwiede
  • 9,868
  • 4
  • 34
  • 82
1
vote
1 answer

Resizing, flushing and closing ByteBuffer

These are actually three questions about how to work with memory mapped files. What I did works, but I'm missing an authoritative answer. I obtain my ByteBuffer like follows: raf = new RandomAccessFile(file, isReadonly ? "r" : "rw"); channel =…
maaartinus
  • 44,714
  • 32
  • 161
  • 320
1
vote
1 answer

Java MappedByteBuffer performance getting worse and worse when you change the map size continuously

Recently I had some tests about Java MappedByteBuffer. I found that if I continuously map the same file and read it, the time spend in reading getting longer and longer. But if I didn't change the map size, It would be faster than the I use the same…
Alexis
  • 1,080
  • 3
  • 21
  • 44