Skip to content

Comparison of different memory management patterns with equivalent implementations in C++ and Java.

Notifications You must be signed in to change notification settings

atsta/CarbageCollectionExperiments

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Equivalent implementations in Java and C++ to compare a language with embedded Garbage Collector, and a language that allow that task for the programmer. Maximum heap size has been se to be proportional to machine's memory.

Case A: Java faster, C++ slower

To make C++ slower compared to the same implementation in Java, we construct objects in memory with big gaps between them, to make the locality as bad as it gets.

g++ -O2 ac++.cpp -o ac++; ./ac++ || javac AJava.java; java -Xmx8G AJava

Case B: Java slower, C++ faster

To make Garbage Collector slower, we construct object of total size to be proportional to machine's memory, and constantly delete them in order to force continuous garbage collection.

g++ -O2 bc++.cpp -o bc++; ./bc++ || javac BJava.java; java -Xmx8G BJava

Same behavior has been observed, with parallel and concurrent GC.

Parallel GC: java -XX:+UseParallelGC -Xmx8G AJava || Concurrent GC: java -XX:+UseG1GC -Xmx8G AJava

About

Comparison of different memory management patterns with equivalent implementations in C++ and Java.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published