Java NIO MappedByteBuffer OutOfMemoryException [英] Java NIO MappedByteBuffer OutOfMemoryException
问题描述
我真的很麻烦:我想用 FileChannel
s和 MappedByteBuffer
s来读取超过几GB的巨大文件 - 我发现的所有文档都意味着使用 FileChannel.map()
方法映射文件相当简单。
当然,有2GB的限制,因为所有的Buffer方法都使用int来表示位置,限制和容量 - 但是系统默认的限制低于这个限制吗?
实际上,我发现很多关于 OutOfMemoryException
s的问题!并没有任何文件,真正定义的限制!
所以 - 我怎样才能将一个符合int限制的文件安全地映射到一个或几个 MappedByteBuffer
s中,而不会只是得到异常?
在尝试 FileChannel.map()
之前,我可以问系统文件的哪个部分可以安全映射吗?怎么样?
为什么有这么少的文档关于这个功能?
文件越大,所需的越少全部在内存中。设计一种方式来一次处理一个缓冲区的文件,一次一行,等等。
MappedByteBuffers特别有问题,因为映射没有定义的版本内存,所以一次使用多个基本上是必然的。
I am really in trouble: I want to read HUGE files over several GB using FileChannel
s and MappedByteBuffer
s - all the documentation I found implies it's rather simple to map a file using the FileChannel.map()
method.
Of course there is a limit at 2GB as all the Buffer methods use int for position, limit and capacity - but what about the system implied limits below that?
In reality, I get lots of problems regarding OutOfMemoryException
s! And no documentation at all that really defines the limits!
So - how can I map a file that fits into the int-limit safely into one or several MappedByteBuffer
s without just getting exceptions?
Can I ask the system which portion of a file I can safely map before I try FileChannel.map()
? How?
Why is there so little documentation about this feature??
The bigger the file, the less you want it all in memory at once. Devise a way to process the file a buffer at a time, a line at a time, etc.
MappedByteBuffers are especially problematic, as there is no defined release of the mapped memory, so using more than one at a time is essentially bound to fail.
这篇关于Java NIO MappedByteBuffer OutOfMemoryException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!