new principle of division between structures and classes

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon Jan 12 20:54:41 PST 2009


Benji Smith wrote:
> Actually, memory allocated in the JVM is very cache-friendly, since two 
> subsequent allocations will always be adjacent to one another in 
> physical memory. And, since the JVM uses a moving GC, long-lived objects 
> move closer and closer together.

Well the problem is that the allocation size grows quickly. Allocate and 
dispose one object per loop -> pages will be quickly eaten.

for (...) {
     JavaClassWithAReallyLongNameAsTheyUsuallyAre o = factory.giveMeOne();
     o.method();
}

The escape analyzer could catch that the variable doesn't survive the 
pass through the loop, but the call to method makes things rather tricky 
(virtual, source unavailable...). So then we're facing a quickly growing 
allocation block and consequently less cache friendliness and more 
frequent collections.


Andrei



More information about the Digitalmars-d mailing list