ディスクベースのファイルと処理するMappedByteBuffersのページングリストを使用している非常に大きなdoubleの配列があります。詳細については、この質問を参照してください。Java1.5を使用してWindowsXPで実行しています。
これが、ファイルに対してバッファの割り当てを行う私のコードの重要な部分です...
try
{
// create a random access file and size it so it can hold all our data = the extent x the size of a double
f = new File(_base_filename);
_filename = f.getAbsolutePath();
_ioFile = new RandomAccessFile(f, "rw");
_ioFile.setLength(_extent * BLOCK_SIZE);
_ioChannel = _ioFile.getChannel();
// make enough MappedByteBuffers to handle the whole lot
_pagesize = bytes_extent;
long pages = 1;
long diff = 0;
while (_pagesize > MAX_PAGE_SIZE)
{
_pagesize /= PAGE_DIVISION;
pages *= PAGE_DIVISION;
// make sure we are at double boundaries. We cannot have a double spanning pages
diff = _pagesize % BLOCK_SIZE;
if (diff != 0) _pagesize -= diff;
}
// what is the difference between the total bytes associated with all the pages and the
// total overall bytes? There is a good chance we'll have a few left over because of the
// rounding down that happens when the page size is halved
diff = bytes_extent - (_pagesize * pages);
if (diff > 0)
{
// check whether adding on the remainder to the last page will tip it over the max size
// if not then we just need to allocate the remainder to the final page
if (_pagesize + diff > MAX_PAGE_SIZE)
{
// need one more page
pages++;
}
}
// make the byte buffers and put them on the list
int size = (int) _pagesize ; // safe cast because of the loop which drops maxsize below Integer.MAX_INT
int offset = 0;
for (int page = 0; page < pages; page++)
{
offset = (int) (page * _pagesize );
// the last page should be just big enough to accommodate any left over odd bytes
if ((bytes_extent - offset) < _pagesize )
{
size = (int) (bytes_extent - offset);
}
// map the buffer to the right place
MappedByteBuffer buf = _ioChannel.map(FileChannel.MapMode.READ_WRITE, offset, size);
// stick the buffer on the list
_bufs.add(buf);
}
Controller.g_Logger.info("Created memory map file :" + _filename);
Controller.g_Logger.info("Using " + _bufs.size() + " MappedByteBuffers");
_ioChannel.close();
_ioFile.close();
}
catch (Exception e)
{
Controller.g_Logger.error("Error opening memory map file: " + _base_filename);
Controller.g_Logger.error("Error creating memory map file: " + e.getMessage());
e.printStackTrace();
Clear();
if (_ioChannel != null) _ioChannel.close();
if (_ioFile != null) _ioFile.close();
if (f != null) f.delete();
throw e;
}
2番目または3番目のバッファーを割り当てた後、タイトルに記載されているエラーが発生します。
使用可能な連続メモリと関係があると思ったので、さまざまなサイズとページ数で試してみましたが、全体的なメリットはありませんでした。
「このコマンドを処理するのに十分なストレージが利用できない」とは正確にはどういう意味で、もしあれば、私はそれについて何ができますか?
MappedByteBuffersのポイントは、ヒープに収まるよりも大きな構造体を処理し、それらをメモリ内にあるかのように処理できることだと思いました。
手がかりはありますか?
編集:
以下の回答(@adsk)に応じて、コードを変更したので、一度に複数のアクティブなMappedByteBufferが存在することはありません。現在マップされていないファイルの領域を参照するときは、既存のマップをジャンクして新しいマップを作成します。約3回のマップ操作の後でも、同じエラーが発生します。
GCがMappedByteBuffersを収集しないことで引用されたバグは、JDK1.5でもまだ問題のようです。