Hi all,
In the interests of speeding up my J3D applications, I'm considering the
pros and cons of the following approach to avoiding memory allocations and
garbage collections. I have created a class called MemoryPool that handles
requests for Transform3Ds (for instance) by returning from a pool of
Transform3Ds an already created Transform3D that is no longer in use. The
calling method could use it and then return it back to the pool of
Transform3Ds free to be used again.
public class MemoryPool{
protected static final Stack transform3Ds = new Stack();
static public Transform3D getTransform3D(){
synchronized( transform3Ds ){
if( transform3Ds.isEmpty() ){
transform3Ds.push( new Transform3D() );
}
return (Transform3D)transform3Ds.pop();
}
}
static public void returnTransform3D( Transform3D T ){
transform3Ds.push( T );
}
}
As an example of usage, the following method
public doSomething(){
Transform3D T = new Transform3D();//causes memory allocation
//do something
}//now eligible for garbage collection
would be written as
public doSomething(){
Transform3D T = MemoryPool.getTransform3D();//no memory allocation
//do something
MemoryPool.returnTransform3D( T );//no garbage collection
}
Please, I am very interested in feedback.
Thanks,
Raffi
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".