001 package javax.realtime; 002 003 /** This is a convenient class to help people figure out 004 * how much memory the need. Instead of passing actual 005 * numbers to the <code>MemoryArea</code> constructors, 006 * one can pass <code>SizeEstimator</code> objects with 007 * which you can have a better feel of how big a memory 008 * area you require. 009 */ 010 public final class SizeEstimator { 011 012 /** The estimated number of bytes neede to store all objects reserved. */ 013 private long estimate; 014 015 public SizeEstimator() {} 016 017 /** Gets an estimate of the number of bytes needed to store 018 * all the objects reserved. 019 * 020 * @return The estimate size in bytes. 021 */ 022 public long getEstimate() { 023 return estimate; 024 } 025 026 /** Take into account additional <code>n</code> instances of <code>Class c</code> 027 * when estimating the size of the <code>MemoryArea</code>. 028 * 029 * @param c The class to take into account. 030 * @param n The number of instances of <code>c</code> to estimate. 031 */ 032 public void reserve(Class c, int n) { 033 estimate += n * objSize(c); 034 } 035 036 /** Take into account an additional instance of <code>SizeEstimator s</code> 037 * when estimating the size of the <code>MemoryArea</code>. 038 * 039 * @param size The given instance of <code>SizeEstimator</code>. 040 */ 041 public void reserve(SizeEstimator size) { 042 estimate += size.estimate; 043 } 044 045 /** Take into account additional <code>n</code> instances of <code>SizeEstimator size</code> 046 * when estimating the size of the <code>MemoryArea</code>. 047 * 048 * @param size The given instance of <code>SizeEstimator</code>. 049 * @param n The number of instances of <code>size</code> to estimate. 050 */ 051 public void reserve(SizeEstimator s, int n) { 052 estimate += n * s.estimate; 053 } 054 055 public native static long objSize(Class c); 056 }