Re: Why use C++ instead of Java?
"Chris M. Thomasson" <no@spam.invalid> wrote in message
news:h8270o$20tu$1@news.ett.com.ua...
[...]
Java version:
___________________________________________________________
public final class tree
{
int m_foo;
public static void main(String[] args) {
for (int i = 0; i < 1000; ++i)
{
tree[] t = new tree[10000000];
}
}
}
___________________________________________________________
[...]
Well, this is not correct. I am not a Java user and just realized that this
does not actually create 10,000,000 tree objects. It just creates an array
that can hold references to 10,000,000 tree objects! So, I need to rewrite
the code like:
___________________________________________________________
public final class tree
{
int m_foo;
public static void main(String[] args) {
tree[] t = new tree[10000000];
for (int i = 0; i < 1000; ++i)
{
for (int x = 0; x < 10000000; ++x)
{
t[x] = new tree();
}
}
}
}
___________________________________________________________
Now I get the following output:
___________________________________________________________
$ time java tree
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at tree.main(tree.java:12)
real 0m1.586s
user 0m0.062s
sys 0m0.031s
___________________________________________________________
That's just great!