diff options
author | Carsten Weisse <[email protected]> | 2005-01-16 15:16:44 +0000 |
---|---|---|
committer | Carsten Weisse <[email protected]> | 2005-01-16 15:16:44 +0000 |
commit | 206af6f53316086e446cfc93a761e4eab6d9ce72 (patch) | |
tree | 96052070bf5a462114f56c80b38775a5fff3e63d /src/jake2/util | |
parent | ee466ee40ab2c6fba6c300651702369195907f9f (diff) |
Simple cache to reduce the garbage of float[3] vectors.
Diffstat (limited to 'src/jake2/util')
-rw-r--r-- | src/jake2/util/Vec3Cache.java | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/jake2/util/Vec3Cache.java b/src/jake2/util/Vec3Cache.java new file mode 100644 index 0000000..1ec2d08 --- /dev/null +++ b/src/jake2/util/Vec3Cache.java @@ -0,0 +1,38 @@ +/* + * Vec3Cache.java + * Copyright (C) 2003 + * + * $Id: Vec3Cache.java,v 1.1 2005-01-16 15:16:44 cawe Exp $ + */ +package jake2.util; + +/** + * Vec3Cache contains float[3] for temporary usage. + * The usage can reduce the garbage at runtime. + * + * @author cwei + */ +public final class Vec3Cache { + + //private static Stack cache = new Stack(); + private static final float[][] cache = new float[64][3]; + private static int index = 0; + private static int max = 0; + + public static final float[] get() { + //max = Math.max(index, max); + return cache[index++]; + } + + public static final void release() { + index--; + } + + public static final void release(int count) { + index-=count; + } + + public static final void debug() { + System.err.println("Vec3Cache: max. " + (max + 1) + " vectors used."); + } +}
\ No newline at end of file |