GC vs. Manual Memory Management Real World Comparison

bearophile bearophileHUGS at lycos.com
Fri Oct 26 07:21:50 PDT 2012


I use this GC thread to show a little GC-related benchmark.

A little Reddit thread about using memory more compactly in Java:

http://www.reddit.com/r/programming/comments/120xvf/compact_offheap_structurestuples_in_java/

The relative blog post:
http://mechanical-sympathy.blogspot.it/2012/10/compact-off-heap-structurestuples-in.html

So I have written a D version, in my test I have reduced the 
amount of memory allocated (NUM_RECORDS = 10_000_000):
http://codepad.org/IhHjqUua

With this lower memory usage the D version it's more than twice 
faster than the compact Java version that uses the same 
NUM_RECORDS (0.5 seconds against 1.2 seconds each loop after the 
first two ones).

In D I have improved the loops, I have used an align() and a 
minimallyInitializedArray, this is not too much bad.

But in the main() I have also had to use a deprecated "delete", 
because otherwise the GC doesn't deallocate the arrays and the 
program burns all the memory (setting the array to null and using 
GC.collect() isn't enough). This is not good.

Bye,
bearophile


More information about the Digitalmars-d-announce mailing list