Cast not your Perl before swine?

Levi Pearson levi at
Tue Dec 18 09:45:59 MST 2007

Dave Smith <dave at> writes:
> Is this a case of the Java interpreter noticing that the contents of
> the loop have no effect, and so it skips it? Does it know because
> class CreateObject has no members, and no non-static methods?
> In the mean time, I'll just assume that Java is capable of allocating
> and freeing 100 million objects in under 1 second. :)

The nice thing about the kind of garbage collector that Java uses is
that allocation becomes REALLY cheap.  The C malloc actually has to do
a fair bit of work to figure out where it can allocate memory from,
since repeated mallocs and frees can cause heap fragmentation.  A
compacting collector makes sure that heaps aren't fragmented, so
allocation becomes a simple pointer increment.  That's the sort of
thing that computers do REALLY fast. :)

Unfortunately for Bryan, most programs do things other than simply
allocating objects in a loop, so the benchmark doesn't tell us a whole
lot about real-world performance.  If you were really writing a C++
program that did something like this, you'd simply write a custom
allocator for that bunch of objects and you'd be back in the same


More information about the PLUG mailing list