001 // CTMemory.java, created by wbeebee 002 // Copyright (C) 2001 Wes Beebee <wbeebee@mit.edu> 003 // Licensed under the terms of the GNU GPL; see COPYING for details. 004 package javax.realtime; 005 006 /** <code>CTMemory</code> represents a constant-sized memory scope. 007 * It uses stack allocation and is very fast and has predictable performance. 008 * @author Wes Beebee <<a href="mailto:wbeebee@mit.edu">wbeebee@mit.edu</a>> 009 */ 010 011 public class CTMemory extends ScopedMemory { 012 013 /** This constructs a CTMemory of the appropriate size (the maximum allowed 014 * to be allocated in the scope). The performance 015 * hit of allocating a large block of memory is taken when this constructor 016 * is called, or reused after refCount drops to zero. 017 */ 018 019 private long minimum; 020 021 public CTMemory(long size) { 022 super(size, size); 023 initNative(size, size); 024 postSetup(); 025 } 026 027 public CTMemory(long minimum, long maximum) { 028 super(maximum); 029 initNative(minimum, maximum); 030 postSetup(); 031 } 032 033 /** Returns a representation of this CTMemory object 034 */ 035 036 public String toString() { 037 return "CTMemory: " + super.toString(); 038 } 039 040 /** Initialize the native component of this MemoryArea 041 * (set up the MemBlock) 042 */ 043 044 protected void initNative(long sizeInBytes) {} 045 046 private native void initNative(long minimum, long maximum); 047 048 /** Invoke this method when you're finished with the MemoryArea 049 * (could be a finalizer if we had finalizers...) 050 */ 051 052 public void done() { 053 doneNative(); 054 } 055 056 /** This will actually free the memory (if refcount = 0). 057 */ 058 059 private native void doneNative(); 060 }