动态增加java堆空间 [英] dynamically increasing java heap space

查看:240
本文介绍了动态增加java堆空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个java程序,用于测试具有不同处理器数量的不同机器上的几个多线程算法的速度。

I have written a java program that tests the speed of a couple of multi-threading algorithms on different machines with various numbers of processors.

在某些机器上,merge sort *失败,因为它需要一个相当大的堆空间才能在非常大的数组上工作。在运行程序之前,我可以自己轻松地更改java堆空间,但我觉得从程序本身开始执行此任务是一种更健壮,更简单的方法。

On some machines, merge sort* fails because it requires a sizable heap space to work on very large arrays. I can easily change the java heap space myself before running the program, but I feel like a more robust and easy approach would be to do this task from within the program itself.

有没有办法在java程序中从虚拟机请求/获得更多堆空间?

Is there a way to request/achieve more heap space from the virtual machine during the course of a java program?

注意:我明白我可以用java -Xmx1g Program这样的脚本执行程序;我对这个问题的好奇心部分是学术性的。

Note: I do understand that I could execute the program with a script like "java -Xmx1g Program"; my curiosity on this subject is in part academic.

*我的实现不会在线合并。它需要O(n)额外的内存。

*My implementation does NOT merge in-line. It requires O(n) extra memory.

推荐答案

Java不能设计为能够动态管理内存,在这种情况下 java堆空间,相反,它的设计是为了减轻程序员不必担心的问题。

Java was not design to be able to dynamically manage memory, in this case "java heap space", all the opposite, it was designed in order to relieve the programmer from having to worry about that.

简而言之,我不敢说没有像malloc() Java中的setHeapSize(int byes)

In short, I'm afraid to say that there is nothing like a "malloc()"or "setHeapSize(int byes)" in Java.

在Java上你限制了可用的内存量程序启动时 JVM 。在内存管理方面,这既是一种祝福,也是一种诅咒。

On Java you're constraint to the amout of memory available to the JVM when your program starts. In terms of memory management this is both a blessing and a curse.

对于这种动态内存分配,你应该尝试使用像 C 这样的语言实现算法和/或者 C ++

For that kind of dynamic memory allocation you should try to use implement your algorithm using a language like C and/or C++ instead.

这篇关于动态增加java堆空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆