Memory Allocation on StateMachine->activate()

Hi,

During tests, I found that the activate of a statemachine makes a memory allocation. When a RT component uses a statemachine with submachines, I think (pretty sure ?!) the component needs to be running to activate the submachine (the submachine needs the component is running to execute its InitState where is the activate of the submachine).

So the first (and only the first) run of the RT component makes a memory allocation. Does anybody has the same problem ... and does anybody has an idea to solve or get round it?

Thanks a lot

Guillaume

Memory Allocation on StateMachine->activate()

Hi Guillaume,

On Wednesday 03 February 2010 18:38:32 gde [..] ... wrote:
> Hi,
>
>
> During tests, I found that the activate of a statemachine makes a memory
> allocation. When a RT component uses a statemachine with submachines, I
> think (pretty sure ?!) the component needs to be running to activate the
> submachine (the submachine needs the component is running to execute its
> InitState where is the activate of the submachine).

You could activate the submachine from the startHook of your component too. A
submachine may be activated before or independent from the parent machine.

>
> So the first (and only the first) run of the RT component makes a memory
> allocation. Does anybody has the same problem ... and does anybody has an
> idea to solve or get round it?

There can be multiple causes. Did you come to this conclusion on an empty
state machine or were there variables declared ? Since activate = initialize
variables (all var's of the entire SM) + execute entry of initial state. The
cause can only be there, or there must be a grave bug in some of the
statemachine or program script code.

Normally, if you activate in startHook(), there isn't a problem anymore ?

Peter

RE : Memory Allocation on StateMachine->activate()

I agree with you : the activate of the root statemachine can be done in startHook if the entry of the initial state only initializes variables.

if we use substatemachine, we need to activate it in the entry of the initial state of the root statemachine (as suggested in the documentation).

StateMachine ParentStateMachine
  {
      SubMachine ChildStateMachine child1
      SubMachine ChildStateMachine child2
      initial state initState
      {
  	entry
          {
	      // enter initial state :
  	    do child1.activate()
  	    do child2.activate()
          }
...

If we activate the root statemachine in the startHook(), the program stops in error on child1.activate()

> Did you come to this conclusion on an empty state machine or were there variables declared ?"

For the tests, root and child statemachines are pretty empty : initialization of some variables (like var int, var double, ...), activate of substatemachines. If the activate of the root statemachine is done in the updateHook, it works (with a memory allocation in updateHook...)

RE : Memory Allocation on StateMachine->activate()

I agree with you : the activate of the root statemachine can be done in startHook if the entry of the initial state only initializes variables.

if we use substatemachine, we need to activate it in the entry of the initial state of the root statemachine (as suggested in the documentation).

StateMachine ParentStateMachine
  {
      SubMachine ChildStateMachine child1
      SubMachine ChildStateMachine child2
      initial state initState
      {
      entry
          {
          // enter initial state :
          do child1.activate()
          do child2.activate()
          }
...

If we activate the root statemachine in the startHook(), the program stops in error on child1.activate()

> Did you come to this conclusion on an empty state machine or were there variables declared ?"

For the tests, root and child statemachines are pretty empty : initialization of some variables (like var int, var double, ...), activate of substatemachines. If the activate of the root statemachine is done in the updateHook, it works (with a memory allocation in updateHook...)

RE : Memory Allocation on StateMachine->activate()

On Thursday 04 February 2010 09:44:23 gde [..] ... wrote:
> I agree with you : the activate of the root statemachine can be done in
> startHook if the entry of the initial state only initializes variables.
>
> if we use substatemachine, we need to activate it in the entry of the
> initial state of the root statemachine (as suggested in the
> documentation).
>
>

> StateMachine ParentStateMachine
>   {
>       SubMachine ChildStateMachine child1
>       SubMachine ChildStateMachine child2
>       initial state initState
>       {
>   	entry
>           {
> 	      // enter initial state :
>   	    do child1.activate()
>   	    do child2.activate()
>           }
> ...
> 

>
> If we activate the root statemachine in the startHook(), the program stops
> in error on child1.activate()

Because it's already active. Just replace the 'do' by a 'try', or omit the
activate statements completely.

>
> > Did you come to this conclusion on an empty state machine or were there
> > variables declared ?"
>
> For the tests, root and child statemachines are pretty empty :
> initialization of some variables (like var int, var double, ...), activate
> of substatemachines. If the activate of the root statemachine is done in
> the updateHook, it works (with a memory allocation in updateHook...)

Then this is troubling. I suggest you open a bug report such that we can track
this issue.

Peter

RE : Memory Allocation on StateMachine->activate()

On Feb 4, 2010, at 03:44 , gde [..] ... wrote:

> I agree with you : the activate of the root statemachine can be done in startHook if the entry of the initial state only initializes variables.
>
> if we use substatemachine, we need to activate it in the entry of the initial state of the root statemachine (as suggested in the documentation).
>
>

> StateMachine ParentStateMachine
>  {
>      SubMachine ChildStateMachine child1
>      SubMachine ChildStateMachine child2
>      initial state initState
>      {
>  	entry
>          {
> 	      // enter initial state :
>  	    do child1.activate()
>  	    do child2.activate()
>          }
> ...
> 

>
> If we activate the root statemachine in the startHook(), the program stops in error on child1.activate()

A long time ago Peter handed out advice to not do anything in the initial state. Keep it as an empty state. We have a similar state machine hierarchy as you are showing here, and get no problems activiating the sub machines. Our initial (empty) state transitions to a SETUP state, which just activates and starts the two submachines and then transitions to the first working state. Not sure if that would help with the above.

I do _not_ know about the memory allocation issue though, in our submachine. Something I would have to test.

>> Did you come to this conclusion on an empty state machine or were there variables declared ?"
>
> For the tests, root and child statemachines are pretty empty : initialization of some variables (like var int, var double, ...), activate of substatemachines. If the activate of the root statemachine is done in the updateHook, it works (with a memory allocation in updateHook...)

Stephen

Memory Allocation on StateMachine->activate()

Hi,

During tests, I found that the activate of a statemachine makes a memory allocation.
When a RT component uses a statemachine with submachines, I think (pretty sure ?!) the component needs to be running to activate the submachine (the submachine needs the component is running to execute its InitState where is the activate of the submachine).

So the first (and only the first) run of the RT component makes a memory allocation.
Does anybody has the same problem ... and does anybody has an idea to solve or get round it?

Thanks a lot

Guillaume