My point wasn't that Java will slow down--it will because eventually the
garbage collector is going to have to do some real work, though the newer
incremental GC techniques should make this average out better. My point was
that the C++ example given isn't realistic nor in any way equivalent to what
the Java is doing. The C++ example never allocates more than one memory
object at time. This just isn't realistic. Allocating and then immediately
deallocating a single memory object doesn't stress the alloc() subsystem at
all. It is the easiest possible scenerio.
-----Original Message-----
From: Nestel, Frank [mailto:[EMAIL PROTECTED]]
Sent: Thursday, August 31, 2000 5:01 AM
To: [EMAIL PROTECTED]
Subject: AW: slow memory allocation problem
Well, I think the example actually shows a slight defect in the
Java allocation mechanism. Though this is probably language
immanent. But the example is fairly extreme and I get the
first few thousand allocations quite fast, so the question is
if such situations regularly occur in "real" programs. IMHO java
performance is often underrated. In most cases the performance
of the programmers is more crucial than the one of the programming
language and in that point Java seems to be superior. There are
of course situations where one needs every bit of performance
and then one would probably avoid Java.
> -----Urspr�ngliche Nachricht-----
> Von: Jim Bailey [mailto:[EMAIL PROTECTED]]
> Gesendet am: Mittwoch, 30. August 2000 17:17
> An: [EMAIL PROTECTED]
> Betreff: Re: slow memory allocation problem
>
> The performance difference is probably based simply on the
> fact that the
> Java example has to do run-time garbage collection and the C++ version
> doesn't have to do any memory management in your example.
> Try allocating a
> large number of heap items from C++ before deleting them.
> Right now you are
> being overly nice to the heap allocation with C++ because you
> never allocate
> more than one heap object at a time. There is no chance that
> you will get
> close to filling up the heap or cause any sort of slowdown
> with your C++
> example.
>
> With Java you are constantly filling the run-time heap and
> then relying on
> garbage collection to clean up after you. Your C++ code is in no way
> equivalent to the Java code. In fact, in comparison to the
> real world, your
> C++ code is pretty useless. No one uses a heap that way in
> the real world.
>
>
> -----Original Message-----
> From: skeptical [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, August 30, 2000 6:31 AM
> To: [EMAIL PROTECTED]
> Subject: slow memory allocation problem
>
>
> guys:
>
> i am doing a benchmark on java memory management. i wrote an
> app to allocate
> and free memory from 1 to 300k bytes. it runs forever. i
> notice it takes
> longer to allocate additional memory as time goes on. the
> same app only
> takes 9 seconds on C++. here's the code listing. can anyone
> pls help out?
>
> tks,
> peter
>
> =======JAVA CODE LISTING =======
> public class Class1
> {
> private static final int NUM_MAX_BYTES = 300000;
>
> public static void main (String[] args)
> {
> int i;
> long t1;
>
> t1 = System.currentTimeMillis();
>
> System.err.print("memory alloc/free 1 - "+NUM_MAX_BYTES+" bytes. ");
> for (i = 0; i < NUM_MAX_BYTES; i++)
> {
> byte[] p;
> p = new byte[i];
> if (i % 1000 == 0)
> {
> // Runtime rt = Runtime.getRuntime();
> // rt.gc();
> System.err.println("current: "+i);
> }
> }
>
> System.err.println("time taken: %d "+
> (System.currentTimeMillis()-t1) +
> "ms");
>
> }
> }
>
>
> ======= C++ CODE LISTING =========
>
> #include "stdafx.h"
> #include <stdio.h>
> #include <windows.h>
>
> #define NUM_MAX_BYTES 300000
>
> int main(int argc, char* argv[])
> {
> int i;
> DWORD t1;
> t1 = GetTickCount();
>
> BYTE * p;
> printf("memory alloc/free 1 - %d bytes. ", NUM_MAX_BYTES);
> for (i = 0; i < NUM_MAX_BYTES; i++)
> {
> p = new BYTE[i];
> delete p;
> }
> printf("time taken: %d ms\n",GetTickCount()-t1);
>
> return 0;
> }
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets