Article:
  Real-Time Java: An Introduction
Subject:   heap or stack
Date:   2006-05-13 10:19:34
From:   simon_massey
i took a look at the digital mars language "D" a while back. it has garbage collection but it also allows you to declare an object on the stack if you don't use the new operator. that was a feature that i had forgotten about C and C++. it occurred to me that java could implement stack objects with annotations. that is to say that if you marked a method as being @DefaultStackObjects the compiler could put any new objects into the stack rather than the heap. of course if you did this you would be constrained by the same constraints as NoHeapRealtimeThread - that objects made on the stack are not assignable to normal object references (i.e. a stack object cannot be assigned to a member field of a heap allocated objects passed into the method nor can it be returned by the method which if the calling method is not also running as @DefaultStackObjects). the difference however that the full real time implementation needs a hard core real time operating system. doing stack objects with annotations could be implemented on a normal operating system. it would not give you a real time guarantee but it would give you "scoped memory objects lite" which would keep garbage generation to a minimum (or zero) if you were careful to only allocate onto the heap what you consider to be immortal to your application.
Full Threads Newest First

Showing messages 1 through 3 of 3.

  • heap or stack
    2006-05-16 03:23:56  simon_massey [View]

    i was thinking that such a @Stack annotation could be ignored by java implimentations that don't understand it - in which case it all goes on the heap. an implimentation that did understand it could do compile time checks to ensure that objects so marked and allocated on the stack are not assigned object variables on the heap. thus giving you cheap and cheerful scoped memory. the sole purpose being to minimise gc activity at the expense of having to constrain your code to not reference object on the stack from the heap.
    • heap or stack
      2006-10-26 03:36:29  asldkfjlkasjflj [View]

      what is heap and stack just explain with diagrams and examples
    • heap or stack
      2006-11-15 11:37:38  kss45 [View]

      I would love to see stack based memory management available outsite the RTSJ. This sounds like a good idea to me.