2 Replies Latest reply on Sep 23, 2008 1:29 PM by 807557

    Avoid completely heap memory usage

      Hi all,
      I'm new with Java RTS and reading the documentation I did not find an answer to my problem.
      I need to write an hard-real time application that musts be as more "safety-critical" as possible, I mean in a way that all the memory necessary is allocated at application's start (so I don't need heap memory) or it's allocated in a controlled way during the application's lifetime (I guess with scope memory usage), practically avoiding dynamic allocation. In this way I would also get rid of the garbage collector using only non heap real time threads and, possibly, event handlers allocated in immortal memory (so gc never interferes heavily with the rest of the application).

      Is there a way to doing this? In other words is there a way to have a kind of an initializer that allocates a fixed number of threads in immortal memory without using even a "bit" of heap memory?

        • 1. Re: Avoid completely heap memory usage
          I'm not clear on your constraint here. It's impossible to start the VM without some heap being used, and some threads of the VM related to the regular class libraries (reference handler thread, signal handler etc) can not execute in a non-heap context. But you can define all your application logic to use non-heap memory by creating the scopes and threads and/or event handlers as needed on startup either in immortal or in scoped memory (only from a real-time thread of course). Remember that all static initializers execute in ImmortalMemory so you can do something like this to get your app up and running not-in-the-heap:
          public class AppStarter {
            static final NoHeapRealtimeThread starter = 
              new NoHeapRealtimeThread(..., ImmortalMemory.instance(),...) {
                public void run() {
                   // this executes in immortal so do all scope creation etc here
            public static void main(String[] args) {
          David Holmes
          • 2. Re: Avoid completely heap memory usage
            I think that solves my problem.
            Thanks for your time!