Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Large usage of RAM in java



Java is a virtual machine, which interprets and compiles your code at run time to make it run on whatever hardware you are using.

You can take the .class file you generated and run that exact same binary, on any of dozens of different computers and it will work on all of them.

The .a (or .exe) file you generated with the C program will run only on the specific CPU/O/S combination you targeted with your compiler.

That's most of the reason.  The other part of the reason is that Java has features, like garbage collection, that C does not.  A lot of those threads are there to provide those features, even if you aren't taking advantage of them.

A more reasonable comparison would be to compare Java to C# on .NET, or Perl, or Python, or Ruby, etc.

Also, the next JDK, 1.7 is supposed to be a lot smarter about loading only stuff you actually need, which will probably make a big difference in special cases like this test.

-Joshua

On Nov 30, 2007, at 12:27 PM, Majd Kokaly wrote:

Greetings,

I tried both programs on my MacBook Pro:
1) simpe while loop in C
int main() { 
int i = 0;
while(1)
 i++;
return 0; 
       }
2) Simple while loop in Java:
class While {
 public static void main (String[] args) {
 int i= 0;
 while (true) {
 i++; 
}
 } 
}

  The first one used 576.00 KB of RAM, 1 Thread and the second one USED 7.63MB, 10 Threads.
Why? Is it the JVM? Why are there 10 Threads?

Any help will be appreciated.
Thanks,

Majd Kokaly
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden

References: 
 >Large usage of RAM in java (From: Majd Kokaly <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.